From 82f95b17669ff8f3615338b4aaf27fdef73d84e6 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 24 Jan 2021 23:04:52 +0100 Subject: [PATCH] feat: add optional extra menu to site navigations (#26) * feat: add optional extra menu to site navigations * add extra menu documentation * rename menu to menu-extra * feat: add optional extra menu to site navigations * add extra menu documentation * rename menu to menu-extra * fix spellcheck --- .dictionary | 1 + exampleSite/content/legal-notice.md | 3 -- exampleSite/content/posts/getting-started.md | 22 ++++++++++++ exampleSite/data/menu/extra.yml | 11 ++++++ layouts/partials/menu-extra.html | 35 ++++++++++++++++++++ layouts/partials/site-footer.html | 30 ++++++----------- layouts/partials/site-header.html | 3 ++ 7 files changed, 83 insertions(+), 22 deletions(-) delete mode 100644 exampleSite/content/legal-notice.md create mode 100644 exampleSite/data/menu/extra.yml create mode 100644 layouts/partials/menu-extra.html diff --git a/.dictionary b/.dictionary index afcdc5c..70f38b6 100644 --- a/.dictionary +++ b/.dictionary @@ -11,6 +11,7 @@ emojify img JSON SVG +YAML pre-processor pre-build submodule diff --git a/exampleSite/content/legal-notice.md b/exampleSite/content/legal-notice.md deleted file mode 100644 index 13fdd23..0000000 --- a/exampleSite/content/legal-notice.md +++ /dev/null @@ -1,3 +0,0 @@ ---- -title: "Legal Notice" ---- diff --git a/exampleSite/content/posts/getting-started.md b/exampleSite/content/posts/getting-started.md index 967f0ac..92c8bad 100644 --- a/exampleSite/content/posts/getting-started.md +++ b/exampleSite/content/posts/getting-started.md @@ -429,3 +429,25 @@ geekblogAnchor: true {{< /tab >}} {{< /tabs >}} + +## Menus + +### Extra menu + +If you want to customize the menus (header and footer), this can be achieved by a data file. This file needs to be written in YAML and placed at data/menu/extra.yml. + +**Example:** + +```Yaml +--- +header: + - name: Github Profile + icon: github + ref: "https://github.com/xoxys" + external: true + +footer: + - name: Contact + icon: email + ref: "/contact" +``` diff --git a/exampleSite/data/menu/extra.yml b/exampleSite/data/menu/extra.yml new file mode 100644 index 0000000..c4b9e8a --- /dev/null +++ b/exampleSite/data/menu/extra.yml @@ -0,0 +1,11 @@ +--- +header: + - name: Github Profile + icon: github + ref: "https://github.com/xoxys" + external: true + +footer: + - name: Contact + icon: email + ref: "/contact" diff --git a/layouts/partials/menu-extra.html b/layouts/partials/menu-extra.html new file mode 100644 index 0000000..a9f46b5 --- /dev/null +++ b/layouts/partials/menu-extra.html @@ -0,0 +1,35 @@ +{{ $current := .current }} +{{ template "menu-file" dict "sect" .source "current" $current "site" $current.Site "target" .target }} + + +{{ define "menu-file" }} +{{ $current := .current }} +{{ $site := .site }} +{{ $target := .target }} + +{{ range sort (default (seq 0) .sect) "weight" }} + {{ if isset . "ref" }} + {{ $this := $site.GetPage .ref }} + {{ $isCurrent := eq $current $this }} + {{ $icon := default false .icon }} + + {{ if eq $target "footer" }} + + {{ if $icon }}{{ end }} + + {{ .name }} + + + {{ else if eq $target "header" }} +
  • + + {{ if $icon }}{{ end }} + {{ .name }} + +
  • + {{ end }} + {{ end }} +{{ end }} +{{ end }} diff --git a/layouts/partials/site-footer.html b/layouts/partials/site-footer.html index 22da2db..3d8d615 100644 --- a/layouts/partials/site-footer.html +++ b/layouts/partials/site-footer.html @@ -1,17 +1,14 @@ diff --git a/layouts/partials/site-header.html b/layouts/partials/site-header.html index 9de1482..5add2b7 100644 --- a/layouts/partials/site-header.html +++ b/layouts/partials/site-header.html @@ -29,5 +29,8 @@ {{ end }} {{ end }} + {{ if .Site.Data.menu.extra.header }} + {{ partial "menu-extra" (dict "current" . "source" .Site.Data.menu.extra.header "target" "header") }} + {{ end }}