From c75289eea7c95972cd8925e75fef12b4d587992d Mon Sep 17 00:00:00 2001 From: Wen Junhua Date: Mon, 27 Nov 2023 23:00:14 +0800 Subject: [PATCH] refactor: refactor headers to use same code --- exampleSite/config/_default/params.toml | 2 +- layouts/partials/header/basic.html | 100 +------- .../partials/header/basic/basic-content.html | 99 ++++++++ layouts/partials/header/hamburger.html | 119 +--------- .../header/hamburger/hamburger-content.html | 118 ++++++++++ layouts/partials/header/hybrid.html | 222 +----------------- 6 files changed, 223 insertions(+), 437 deletions(-) create mode 100644 layouts/partials/header/basic/basic-content.html create mode 100644 layouts/partials/header/hamburger/hamburger-content.html diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 3038930a..25b5bad4 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -19,7 +19,7 @@ enableQuicklink = true fingerprintAlgorithm = "sha256" [header] - layout = "basic" # valid options: basic, hamburger, hybrid, custom + layout = "hybrid" # valid options: basic, hamburger, hybrid, custom # logo = "img/logo.jpg" # logoDark = "img/dark-logo.jpg" showTitle = true diff --git a/layouts/partials/header/basic.html b/layouts/partials/header/basic.html index 480d8fe7..bd5fadd5 100644 --- a/layouts/partials/header/basic.html +++ b/layouts/partials/header/basic.html @@ -7,105 +7,7 @@ {{/* Main menu */}} {{ if or .Site.Menus.main (.Site.Params.enableSearch | default false) }} {{ end }} diff --git a/layouts/partials/header/basic/basic-content.html b/layouts/partials/header/basic/basic-content.html new file mode 100644 index 00000000..3b4d7d65 --- /dev/null +++ b/layouts/partials/header/basic/basic-content.html @@ -0,0 +1,99 @@ +{{ if .Site.Menus.main }} + {{ range .Site.Menus.main }} + {{ if and (eq .Params.action "locale") (or (not page.IsTranslated) (not site.IsMultiLingual)) }} + {{ continue }} + {{ end }} +
  • + {{ if eq .Params.action "search" }} + {{ $.Scratch.Add "searchCount" 1 }} + {{ if $.Site.Params.enableSearch | default false }} + + {{ end }} + {{ else if eq .Params.action "appearance" }} + {{ $.Scratch.Add "switchCount" 1 }} + + {{ else if eq .Params.action "locale" }} + {{ $.Scratch.Add "localeCount" 1 }} + {{ partial "translations.html" . }} + {{ else }} + {{ with .Params.icon }} + + {{- partial "icon.html" . -}} + + {{- end -}}{{- if .Params.showName | default true -}} + {{ .Name | markdownify | emojify }} + {{ end }} + {{ end }} +
  • + {{ end }} + {{ if and ($.Site.Params.enableSearch | default false) (eq ($.Scratch.Get "searchCount") 0) }} +
  • + +
  • + {{ end }} +{{ end }} \ No newline at end of file diff --git a/layouts/partials/header/hamburger.html b/layouts/partials/header/hamburger.html index fbd5e12c..c0df5dcb 100644 --- a/layouts/partials/header/hamburger.html +++ b/layouts/partials/header/hamburger.html @@ -7,124 +7,7 @@ {{/* Hamburger menu */}} {{ if or .Site.Menus.main (.Site.Params.enableSearch | default false) }} {{ end }} diff --git a/layouts/partials/header/hamburger/hamburger-content.html b/layouts/partials/header/hamburger/hamburger-content.html new file mode 100644 index 00000000..bcf2f45d --- /dev/null +++ b/layouts/partials/header/hamburger/hamburger-content.html @@ -0,0 +1,118 @@ + +
    + {{ partial "icon.html" "bars" }} +
    + \ No newline at end of file diff --git a/layouts/partials/header/hybrid.html b/layouts/partials/header/hybrid.html index 69aba1e1..2055bab9 100644 --- a/layouts/partials/header/hybrid.html +++ b/layouts/partials/header/hybrid.html @@ -5,229 +5,13 @@ {{ partial "logo.html" . }} {{ if or .Site.Menus.main (.Site.Params.enableSearch | default false) }} - {{/* Hamburger menu */}} {{/* Basic menu */}} {{ end }}