refactor: move params.toml>address_formats --> data/address_formats.toml

BREAKING CHANGE:
Possible breaking change for sites using custom address formats.
Override `address_formats.toml` to add custom address formats for a site.
This commit is contained in:
George Cushen 2020-08-23 19:43:36 +01:00
commit 1f6d31c93a
3 changed files with 12 additions and 12 deletions

View file

@ -0,0 +1,6 @@
# Address formats.
en-us = {order = ['street', 'city', 'region', 'postcode'], delimiters = [', ', ', ', ' ', '']}
en-gb = {order = ['street', 'city', 'region', 'postcode'], delimiters = [', ', ', ', ', ', '']}
de = {order = ['street', 'postcode', 'city'], delimiters = ['<br>', ' ', '']}
fr-fr = {order = ['street', 'postcode', 'city'], delimiters = ['<br>', ' ', '']}
zh = {order = ['postcode', 'region', 'city', 'street'], delimiters = [' ', ' ', ' ', '']}

View file

@ -139,7 +139,7 @@ date_format = "Jan 2, 2006"
# Examples: "3:04 pm" or "15:04"
time_format = "3:04 PM"
# Address format (choose from the [address_formats] list below or add you own to the list).
# Address format (en-us, en-gb, de, fr-fr, zh).
address_format = "en-us"
############################
@ -186,14 +186,6 @@ plugins_js = []
# Choose a shape for avatar images. Options: circle, square.
shape = "circle"
# Available address formats.
[address_formats]
en-us = {order = ['street', 'city', 'region', 'postcode'], delimiters = [', ', ', ', ' ', '']}
en-gb = {order = ['street', 'city', 'region', 'postcode'], delimiters = [', ', ', ', ', ', '']}
de = {order = ['street', 'postcode', 'city'], delimiters = ['<br>', ' ', '']}
fr-fr = {order = ['street', 'postcode', 'city'], delimiters = ['<br>', ' ', '']}
zh = {order = ['postcode', 'region', 'city', 'street'], delimiters = [' ', ' ', ' ', '']}
# Configuration of publication pages.
[publications]
# Date format (refer to https://sourcethemes.com/academic/docs/customization/#date-format )

View file

@ -1,13 +1,15 @@
{{/* Function to return a formatted address given a semantic address. */}}
{{/* Check for valid site config. */}}
{{ if not site.Params.address_format }}{{errorf "Address format missing from `params.toml`!"}}{{end}}
{{ if not site.Params.address_formats }}{{errorf "Address formats missing from `params.toml`!"}}{{end}}
{{ if not site.Data.address_formats }}{{errorf "Address formats missing from `data/address_formats.toml`!"}}{{end}}
{{ $page := . }}
{{ $address := .address }}
{{ $format_name := $page.Params.address_format | default site.Params.address_format | default "en-us" }}
{{ $format := index site.Params.address_formats $format_name }}
{{ if not (isset site.Data.address_formats $format_name) }}{{ errorf "Address format `%s` missing from `data/address_formats.toml`!" $format_name }}{{end}}
{{ $format := index site.Data.address_formats $format_name }}
{{ $address_display := slice }}
{{ range $k, $v := $format.order }}