From fc5656c937629b9610937cf803a747bef4707129 Mon Sep 17 00:00:00 2001 From: Kaligule Date: Sat, 1 May 2021 23:57:19 +0200 Subject: [PATCH] Allow footer configuration (#303) * Allow to disable the footer with params.footer.enable = false Default is to have the footer enabled (to keep backwards compatibility). The diff looks much worse than it is, I just added a variable and an if clause, but then had to indent the rest of the file. Make footerEnabled an explicit variable. This should improve readability. Use default parameter for even more readability. * Allow to enable/disable the "contact me" section in the footer. Just set `footer.contactMe.enable` in the config. Default is true, for backwards compatibility. * Make footer template more consistent. Enabling footers elements and the newsletter is now managed in the same place. * Allow to disable the footer navigation. Default is enabled. * Allow to disable credentials and copyright notice. Default: enabled * Footer: Reformat variable initialization for readability. * Allow providing template for footer Signed-off-by: hossainemruz Co-authored-by: hossainemruz --- layouts/_default/baseof.html | 3 +- layouts/index.html | 3 +- layouts/partials/footer.html | 219 +++++++++++++++++++---------------- 3 files changed, 122 insertions(+), 103 deletions(-) diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 2a5935f..f733092 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -30,7 +30,8 @@ - {{- partial "footer.html" . -}} + {{ $footerTemplate:= site.Params.footer.template | default "footer.html" }} + {{- partial $footerTemplate . -}} {{ partial "scripts.html" . }} diff --git a/layouts/index.html b/layouts/index.html index e960ebd..9a5d5dd 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -66,7 +66,8 @@ {{ end }} - {{- partial "footer.html" . -}} + {{ $footerTemplate:= site.Params.footer.template | default "footer.html" }} + {{- partial $footerTemplate . -}} {{ partial "scripts.html" . }} diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 1503025..a20f226 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -1,112 +1,129 @@ -{{ $author:= site.Data.author }} -{{ if (index site.Data site.Language.Lang).author }} - {{ $author = (index site.Data site.Language.Lang).author }} +{{/* variables for enabling/disabling parts of the footer */}} +{{ $footerEnabled := site.Params.footer.enable | default true }} +{{ $navigationEnabled := site.Params.footer.navigation.enable | default true }} +{{ $contactMeEnabled := site.Params.footer.contactMe.enable | default true }} +{{ $newsletterEnabled := site.Params.footer.newsletter.enable | default true }} +{{ $credentialsEnabled := site.Params.footer.credentials.enable | default true }} + +{{/* Keep backward compatibility for the newsletter function */}} +{{ if site.Params.newsletter.enable }} + {{ $newsletterEnabled = true }} {{ end }} -{{ $sections:= site.Data.sections }} -{{ if (index site.Data site.Language.Lang).sections }} - {{ $sections = (index site.Data site.Language.Lang).sections }} -{{ end }} - -{{ $copyrightNotice := "© 2020 Copyright."}} -{{ if (index site.Data site.Language.Lang).site }} - {{ $siteConfig := (index site.Data site.Language.Lang).site }} - {{ if $siteConfig.copyright }} - {{ $copyrightNotice = $siteConfig.copyright }} +{{ if $footerEnabled }} + {{ $author:= site.Data.author }} + {{ if (index site.Data site.Language.Lang).author }} + {{ $author = (index site.Data site.Language.Lang).author }} {{ end }} -{{ end }} -{{/* footer logos */}} -{{ $themeLogo := "/images/theme-logo.png" }} -{{ $hugoLogo := "/images/hugo-logo.svg" }} + {{ $sections:= site.Data.sections }} + {{ if (index site.Data site.Language.Lang).sections }} + {{ $sections = (index site.Data site.Language.Lang).sections }} + {{ end }} -{{/* resize the logos. don't resize svg because it is not supported */}} -{{ $themeLogo:= resources.Get $themeLogo}} -{{ if and $themeLogo (ne $themeLogo.MediaType.SubType "svg") }} - {{ $themeLogo = $themeLogo.Resize "32x" }} -{{ end }} -{{ $themeLogo = $themeLogo.RelPermalink}} + {{ $copyrightNotice := "© 2021 Copyright."}} + {{ if (index site.Data site.Language.Lang).site }} + {{ $siteConfig := (index site.Data site.Language.Lang).site }} + {{ if $siteConfig.copyright }} + {{ $copyrightNotice = $siteConfig.copyright }} + {{ end }} + {{ end }} -{{ $hugoLogo:= resources.Get $hugoLogo}} -{{ if and $hugoLogo (ne $hugoLogo.MediaType.SubType "svg")}} - {{ $hugoLogo = $hugoLogo.Resize "32x" }} -{{ end }} -{{ $hugoLogo = $hugoLogo.RelPermalink}} + {{/* footer logos */}} + {{ $themeLogo := "/images/theme-logo.png" }} + {{ $hugoLogo := "/images/hugo-logo.svg" }} -
-
-
-
-
{{ i18n "navigation" }}
- {{ if $sections }} -
    - {{- range sort $sections "section.weight" }} - {{ if and (.section.enable) (.section.showOnNavbar)}} - {{ $sectionID := replace (lower .section.name) " " "-" }} - {{ if .section.id }} - {{ $sectionID = .section.id }} + {{/* resize the logos. don't resize svg because it is not supported */}} + {{ $themeLogo:= resources.Get $themeLogo}} + {{ if and $themeLogo (ne $themeLogo.MediaType.SubType "svg") }} + {{ $themeLogo = $themeLogo.Resize "32x" }} + {{ end }} + {{ $themeLogo = $themeLogo.RelPermalink}} + + {{ $hugoLogo:= resources.Get $hugoLogo}} + {{ if and $hugoLogo (ne $hugoLogo.MediaType.SubType "svg")}} + {{ $hugoLogo = $hugoLogo.Resize "32x" }} + {{ end }} + {{ $hugoLogo = $hugoLogo.RelPermalink}} + +
    +
    +
    + {{ if $navigationEnabled }} +
    +
    {{ i18n "navigation" }}
    + {{ if $sections }} +
      + {{- range sort $sections "section.weight" }} + {{ if and (.section.enable) (.section.showOnNavbar)}} + {{ $sectionID := replace (lower .section.name) " " "-" }} + {{ if .section.id }} + {{ $sectionID = .section.id }} + {{ end }} + {{ end }} - - {{ end }} - {{- end }} -
    - {{ end }} - -
    - {{ if $author }} -
    -
    {{ i18n "contact_me" }}
    -
      - {{ range $key,$value:= $author.contactInfo }} -
    • {{ title $key }}: {{ $value }}
    • + {{- end }} +
    {{ end }} -
-
- {{ end }} - {{ if site.Params.newsletter.enable }} -
- -

{{ i18n "newsletter_text" }}

-
-
- - {{ i18n "newsletter_warning" }} -
- -
-
- {{ end }} -
-
-
-
-
- -
{{ $copyrightNotice | markdownify }}
- + {{ end }} + {{ if (and $contactMeEnabled $author) }} +
+
{{ i18n "contact_me" }}
+
    + {{ range $key,$value:= $author.contactInfo }} +
  • {{ title $key }}: {{ $value }}
  • + {{ end }} +
+
+ {{ end }} + {{ if $newsletterEnabled }} +
+ +

{{ i18n "newsletter_text" }}

+
+
+ + {{ i18n "newsletter_warning" }} +
+ +
+
+ {{ end }}
- -
+ {{ if $credentialsEnabled }} +
+
+
+ +
{{ $copyrightNotice | markdownify }}
+ +
+
+ {{ end }} + +{{end}}