Sfoglia il codice sorgente

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 <hossainemruz@gmail.com>

Co-authored-by: hossainemruz <hossainemruz@gmail.com>
Kaligule 4 anni fa
parent
commit
fc5656c937
3 ha cambiato i file con 118 aggiunte e 99 eliminazioni
  1. 2 1
      layouts/_default/baseof.html
  2. 2 1
      layouts/index.html
  3. 114 97
      layouts/partials/footer.html

+ 2 - 1
layouts/_default/baseof.html

@@ -30,7 +30,8 @@
     </div>
 
     <!------- ADD FOOTER ------------>
-    {{- partial "footer.html" . -}}
+    {{ $footerTemplate:= site.Params.footer.template | default "footer.html" }}
+    {{- partial $footerTemplate . -}}
 
     <!------- ADD COMMON SCRIPTS ------->
     {{ partial "scripts.html" . }}

+ 2 - 1
layouts/index.html

@@ -66,7 +66,8 @@
     {{ end }}
 
     <!--- ADD FOOTER ----------------------->
-    {{- partial "footer.html" . -}}
+    {{ $footerTemplate:= site.Params.footer.template | default "footer.html" }}
+    {{- partial $footerTemplate . -}}
 
     <!--- ADD COMMON SCRIPTS --------------->
     {{ partial "scripts.html" . }}

+ 114 - 97
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 }}
-{{ end }}
+{{/*  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 }}
 
-{{ $sections:= site.Data.sections }}
-{{ if (index site.Data site.Language.Lang).sections }}
-  {{ $sections = (index site.Data site.Language.Lang).sections }}
+{{/*  Keep backward compatibility for the newsletter function */}}
+{{ if site.Params.newsletter.enable }}
+  {{ $newsletterEnabled = true }}
 {{ 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" }}
+
+  {{/* 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}}
 
-<footer class="container-fluid text-center align-content-center footer pb-2">
-  <div class="container pt-5">
-    <div class="row text-left">
-      <div class="col-md-4 col-sm-12">
-        <h5>{{ i18n "navigation" }}</h5>
-        {{ if $sections }}
-        <ul>
-          {{- range sort $sections "section.weight" }}
-            {{ if and (.section.enable) (.section.showOnNavbar)}}
-              {{ $sectionID := replace (lower .section.name) " " "-"  }}
-              {{ if .section.id }}
-                {{ $sectionID = .section.id }}
+  <footer class="container-fluid text-center align-content-center footer pb-2">
+    <div class="container pt-5">
+      <div class="row text-left">
+        {{ if $navigationEnabled }}
+        <div class="col-md-4 col-sm-12">
+          <h5>{{ i18n "navigation" }}</h5>
+          {{ if $sections }}
+          <ul>
+            {{- range sort $sections "section.weight" }}
+              {{ if and (.section.enable) (.section.showOnNavbar)}}
+                {{ $sectionID := replace (lower .section.name) " " "-"  }}
+                {{ if .section.id }}
+                  {{ $sectionID = .section.id }}
+                {{ end }}
+                <li class="nav-item">
+                  <a class="smooth-scroll" href="/#{{ $sectionID }}">{{ .section.name }}</a>
+                </li>
               {{ end }}
-              <li class="nav-item">
-                <a class="smooth-scroll" href="/#{{ $sectionID }}">{{ .section.name }}</a>
-              </li>
+            {{- end }}
+          </ul>
+          {{ end }}
+        </div>
+        {{ end }}
+        {{ if (and $contactMeEnabled $author) }}
+        <div class="col-md-4 col-sm-12">
+          <h5>{{ i18n "contact_me" }}</h5>
+          <ul>
+            {{ range $key,$value:= $author.contactInfo }}
+            <li><span>{{ title $key }}: </span> <span>{{ $value }}</span></li>
             {{ end }}
-          {{- end }}
-        </ul>
+          </ul>
+        </div>
+        {{ end }}
+        {{ if $newsletterEnabled }}
+        <div class="col-md-4 col-sm-12">
+          <!-- <h5>Newsletter</h5> -->
+          <p>{{ i18n "newsletter_text" }}</p>
+          <form>
+            <div class="form-group">
+              <input
+                type="email"
+                class="form-control"
+                id="exampleInputEmail1"
+                aria-describedby="emailHelp"
+                placeholder="{{ i18n "newsletter_input_placeholder" }}"
+              />
+              <small id="emailHelp" class="form-text text-muted"
+                >{{ i18n "newsletter_warning" }}</small
+              >
+            </div>
+            <button type="submit" class="btn btn-info">{{ i18n "submit" }}</button>
+          </form>
+        </div>
         {{ end }}
-
-      </div>
-      {{ if $author }}
-      <div class="col-md-4 col-sm-12">
-        <h5>{{ i18n "contact_me" }}</h5>
-        <ul>
-          {{ range $key,$value:= $author.contactInfo }}
-          <li><span>{{ title $key }}: </span> <span>{{ $value }}</span></li>
-          {{ end }}
-        </ul>
-      </div>
-      {{ end }}
-      {{ if site.Params.newsletter.enable }}
-      <div class="col-md-4 col-sm-12">
-        <!-- <h5>Newsletter</h5> -->
-        <p>{{ i18n "newsletter_text" }}</p>
-        <form>
-          <div class="form-group">
-            <input
-              type="email"
-              class="form-control"
-              id="exampleInputEmail1"
-              aria-describedby="emailHelp"
-              placeholder="{{ i18n "newsletter_input_placeholder" }}"
-            />
-            <small id="emailHelp" class="form-text text-muted"
-              >{{ i18n "newsletter_warning" }}</small
-            >
-          </div>
-          <button type="submit" class="btn btn-info">{{ i18n "submit" }}</button>
-        </form>
       </div>
-      {{ end }}
     </div>
-  </div>
-  <hr />
-  <div class="container">
-    <div class="row text-left">
-      <div class="col-md-4">
-        <a id="theme" href="https://github.com/hossainemruz/toha" target="_blank" rel="noopener">
-          <img src="{{ $themeLogo }}" alt="Toha Theme Logo">
-          Toha
-        </a>
-      </div>
-      <div class="col-md-4 text-center">{{ $copyrightNotice | markdownify }}</div>
-      <div class="col-md-4 text-right">
-        <a id="hugo" href="https://gohugo.io/" target="_blank" rel="noopener">{{ i18n "hugoAttributionText" }}
-        <img
-          src="{{ $hugoLogo }}"
-          alt="Hugo Logo"
-          height="18"
-        />
-        </a>
+    {{ if $credentialsEnabled }}
+    <hr />
+    <div class="container">
+      <div class="row text-left">
+        <div class="col-md-4">
+          <a id="theme" href="https://github.com/hossainemruz/toha" target="_blank" rel="noopener">
+            <img src="{{ $themeLogo }}" alt="Toha Theme Logo">
+            Toha
+          </a>
+        </div>
+        <div class="col-md-4 text-center">{{ $copyrightNotice | markdownify }}</div>
+        <div class="col-md-4 text-right">
+          <a id="hugo" href="https://gohugo.io/" target="_blank" rel="noopener">{{ i18n "hugoAttributionText" }}
+          <img
+            src="{{ $hugoLogo }}"
+            alt="Hugo Logo"
+            height="18"
+          />
+          </a>
+        </div>
       </div>
     </div>
-  </div>
-</footer>
+    {{ end }}
+  </footer>
+{{end}}