Handle website contacts dynamically

This commits change the way contacts params are handled: instead of
declaring them statically, they are declared as an array of tables in
the TOML configuration file, then they are displayed in the two sections
(homepage and footer) of the website through the {{ range }} statement.

This makes handling multiple contacts params easier and avoids the
need of changing manually this two files:
- `layouts/partials/footer.html`;
- `exampleSite/content/homepage/contact.md`;

Signed-off-by: Filippo Fontana <filippofontana1998@gmail.com>
This commit is contained in:
Filippo Fontana 2024-03-09 16:33:59 +01:00 committed by zjedi
parent 2d94f7449a
commit 69acce5ec7
4 changed files with 20 additions and 10 deletions

View file

@ -61,6 +61,14 @@ title = "Jane Doe - Nutrition Coach & Chef Consultant"
[params.meta]
keywords = "some, keywords, for, seo, you, know, google, duckduckgo, and, such"
[params.contact]
email = "mail@janedoe.com"
phone = "+49 1111 555555"
[[params.contacts]]
label = "phone"
value = "+49 1111 555555"
url = "tel: +49 1111 555555"
icon = "fa fa-phone"
[[params.contacts]]
label = "email"
value = "mail@janedoe.com"
url = "mailto: mail@janedoe.com"
icon = "fa fa-envelope"

View file

@ -4,8 +4,6 @@ weight: 4
header_menu: true
---
{{<icon class="fa fa-envelope">}}&nbsp;[{{<email>}}](mailto:{{<email>}})
{{<icon class="fa fa-phone">}}&nbsp;[{{<phone>}}](tel:{{<phone>}})
{{<contact_list>}}
Let us get in touch!

View file

@ -18,14 +18,15 @@
{{ end }}
{{ if ne .Site.Params.footer.showContactIcons false }}
{{ with .Site.Params.contact }}
<section class="icons">
<ol>
<li><a href="mailto:{{ .email }}" aria-label='{{ i18n "email" }}'><i class="fa fa-envelope"></i></a></li>
<li><a href="tel:{{ .phone }}" aria-label='{{ i18n "phone" }}'><i class="fa fa-phone"></i></a></li>
{{ range .Site.Params.contacts }}
<li>
<a href="{{ .url }}" aria-label='{{ i18n "{{ .label }}" }}'><i class="{{ .icon }}"></i></a>
</li>
{{ end }}
</ol>
</section>
{{ end }}
{{ end }}
{{ with .Site.Params.copyright }}

View file

@ -0,0 +1,3 @@
{{ range .Site.Params.contacts }}
<p><i class="{{ .icon}}"></i>&nbsp;<a href="{{ .url }}">{{ .value }}</a></p>
{{ end }}