From 79b43fcfce316113e7e887422d7fda38ba9baa19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Tue, 22 Oct 2024 19:35:10 +0200 Subject: [PATCH] menu: support nested Hugo menus #423 --- README.md | 4 +- assets/css/theme.css | 12 +- exampleSite/config/_default/hugo.toml | 28 +- exampleSite/config/_default/params.toml | 59 ++++- .../frontmatter/navigationmenu/_index.en.md | 1 - .../frontmatter/reference/frontmatter.toml | 30 +++ .../sidebar/shortcutmenu/_index.en.md | 70 +++-- .../introduction/releasenotes/7/1.en.md | 25 ++ exampleSite/content/more/credits/_index.en.md | 3 + .../content/more/credits/_index.pir.md | 3 + exampleSite/content/showcase/_index.en.md | 1 + exampleSite/content/showcase/_index.pir.md | 1 + exampleSite/i18n/art-x-pir.toml | 2 +- i18n/ar.toml | 2 +- i18n/cs.toml | 2 +- i18n/de.toml | 2 +- i18n/en.toml | 2 +- i18n/es.toml | 2 +- i18n/fi.toml | 2 +- i18n/fr.toml | 2 +- i18n/hi.toml | 2 +- i18n/hu.toml | 2 +- i18n/id.toml | 2 +- i18n/it.toml | 2 +- i18n/ja.toml | 2 +- i18n/ko.toml | 2 +- i18n/nl.toml | 2 +- i18n/pl.toml | 2 +- i18n/pt.toml | 2 +- i18n/ro.toml | 2 +- i18n/ru.toml | 2 +- i18n/sw.toml | 2 +- i18n/tr.toml | 2 +- i18n/vi.toml | 2 +- i18n/zh-CN.toml | 2 +- i18n/zh-Hans.toml | 2 +- i18n/zh-Hant.toml | 2 +- i18n/zh-TW.toml | 2 +- i18n/zh.toml | 2 +- layouts/partials/menu.html | 250 ++++++++++++++---- layouts/partials/menupermalink.gotmpl | 10 + layouts/partials/menutitle.gotmpl | 12 + layouts/partials/title.gotmpl | 3 - layouts/partials/version.txt | 2 +- theme.toml | 2 +- 45 files changed, 429 insertions(+), 141 deletions(-) create mode 100644 exampleSite/content/introduction/releasenotes/7/1.en.md create mode 100644 layouts/partials/menupermalink.gotmpl create mode 100644 layouts/partials/menutitle.gotmpl diff --git a/README.md b/README.md index 9b6169295e..f67b5c182c 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ The Relearn theme is an enhanced fork of the popular [Learn theme](https://githu - [Chapter and site-wide printing capabilities](https://mcshelby.github.io/hugo-theme-relearn/configuration/sitemanagement/outputformats#print-support) - [Versatile search options: in-page, popup, and dedicated search page](https://mcshelby.github.io/hugo-theme-relearn/configuration/sidebar/search) - [Customizable top bar buttons](https://mcshelby.github.io/hugo-theme-relearn/configuration/customization/topbar) - - [Nested navigation menu](https://mcshelby.github.io/hugo-theme-relearn/authoring/frontmatter/navigationmenu) - - [Configurable menu shortcuts](https://mcshelby.github.io/hugo-theme-relearn/configuration/sidebar/shortcutmenu) + - [Nested menus](https://mcshelby.github.io/hugo-theme-relearn/authoring/frontmatter/navigationmenu) + - [Configurable menus](https://mcshelby.github.io/hugo-theme-relearn/configuration/sidebar/shortcutmenu) - [Support for hidden pages](https://mcshelby.github.io/hugo-theme-relearn/configuration/content/hidden) - [Comprehensive taxonomy support](https://mcshelby.github.io/hugo-theme-relearn/configuration/customization/taxonomy) - [Social media integration](https://mcshelby.github.io/hugo-theme-relearn/configuration/sitemanagement/meta#social-media-images) diff --git a/assets/css/theme.css b/assets/css/theme.css index b710a0f98b..87b1296699 100644 --- a/assets/css/theme.css +++ b/assets/css/theme.css @@ -310,6 +310,14 @@ a:focus, margin-right: 0; } +#R-sidebar .R-sidebarmenu > ul { + margin-top: 1rem; +} + +#R-sidebar .R-sidebarmenu > .nav-title ~ ul { + margin-top: .8rem; +} + #R-sidebar ul { list-style: none; padding: 0; @@ -2685,10 +2693,6 @@ body #R-logo svg * { padding-bottom: 1rem; } -#R-topics { - padding-top: 1rem; -} - article .R-taxonomy ul, article .R-taxonomy li { list-style: none; diff --git a/exampleSite/config/_default/hugo.toml b/exampleSite/config/_default/hugo.toml index 8b00be6f94..0888baf13d 100644 --- a/exampleSite/config/_default/hugo.toml +++ b/exampleSite/config/_default/hugo.toml @@ -106,28 +106,30 @@ summaryLength = 10 landingPageName = ' Home' [[languages.en.menu.shortcuts]] - name = ' GitHub Repo' - identifier = 'ds' + pre = ' ' + name = 'GitHub Repo' url = 'https://github.com/McShelby/hugo-theme-relearn' weight = 10 [[languages.en.menu.shortcuts]] - name = ' Showcases' + name = 'Showcases' pageRef = '/showcase' weight = 20 [[languages.en.menu.shortcuts]] - name = ' Credits' + name = 'Credits' pageRef = '/more/credits' weight = 30 [[languages.en.menu.shortcuts]] - name = ' Tags' + pre = ' ' + name = 'Tags' pageRef = '/tags' weight = 40 [[languages.en.menu.shortcuts]] - name = ' Categories' + pre = ' ' + name = 'Categories' pageRef = '/categories' weight = 50 @@ -152,28 +154,30 @@ summaryLength = 10 landingPageName = ' Arrr! Home' [[languages.pir.menu.shortcuts]] - name = ' GitHub Repo' - identifier = 'ds' + pre = ' ' + name = 'GitHub Repo' url = 'https://github.com/McShelby/hugo-theme-relearn' weight = 10 [[languages.pir.menu.shortcuts]] - name = ' Showcases' + pre = ' ' + name = 'Showcases' pageRef = '/showcase' weight = 20 [[languages.pir.menu.shortcuts]] - name = ' Crrredits' + name = 'Crrredits' pageRef = '/more/credits' weight = 30 [[languages.pir.menu.shortcuts]] - name = ' Arrr! Tags' + name = 'Arrr! Tags' pageRef = '/tags' weight = 40 [[languages.pir.menu.shortcuts]] - name = ' Categorrries' + pre = ' ' + name = 'Categorrries' pageRef = '/categories' weight = 50 diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index d1b43443b2..3371943ba2 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -196,6 +196,13 @@ additionalContentLanguage = [ 'en' ] # Menu # These options modify the menu appearance. +# Shows checkmarks for visited pages of the main menu. +# Default: false +# This also causes the display of the `Clear History` entry in the lower part +# of the menu to remove all checkmarks. The checkmarks will also been removed +# if you regenerate your site as the ids are not stable. +showVisitedLinks = true + # Hide the Home entry. # Default: false # If shown, a Home button will appear below the search bar and the main menu. @@ -225,19 +232,6 @@ alwaysopen = '' # This can be overridden in the page's frontmatter. collapsibleMenu = true -# Shows checkmarks for visited pages of the main menu. -# Default: false -# This also causes the display of the `Clear History` entry in the lower part -# of the menu to remove all checkmarks. The checkmarks will also been removed -# if you regenerate your site as the ids are not stable. -showVisitedLinks = true - -# Hide heading above the shortcut menu. -# Default: false -# The title for the heading can be overwritten in your i18n files. See Hugo's -# documentation how to do this. -disableShortcutsTitle = false - # Hide the language switcher. # Default: false # If you have more than one language configured, a language switcher is @@ -245,6 +239,45 @@ disableShortcutsTitle = false # turn this behavior off. disableLanguageSwitchingButton = false +# Hide heading above the shortcuts menu. +# Default: false +# If a sidebar menu with identifier `shortcuts` is configured (see below), +# this is the easy way to remove the heading; +# The title for the heading can be overwritten in your i18n files. See Hugo's +# documentation how to do this. +disableShortcutsTitle = false + +# Define your own sidebar menus. +# Default: the value used below +# The sidebar menus are built from this parameter. If not set, it contains +# the below default. +# Menus are written from the sidebar's top to buttom in the order given in +# this array. +# This can be overridden in the page's frontmatter. +# Each entry can contain the following keys: +# - `type` is mandatory. Either `page` in case it should generate a tre from +# the page structure or `menu` in case it should generate a tree from a +# defined menu. +# - `identifier` is mandatory. In case of `type=page`, anything can be used, +# in case of `type=menu` the `identifier` key must be identical to the +# key of the menu definition. +# - `main`, boolean. If `true`, the first tree level is spaced more generous +# and the text is emphasized. Default: `true` for `type=page` and `false` +# for `type=menu` +# - `disableTitle`, boolean. If `true`, there is no title above the tree. +# Default: `true` for `type=page` and `false` for `type=menu`. If a title +# should be used, in case of `type=page` it will be taken from the page's +# `menuTitle` front matter and if not set, from the translation files, using +# the menu `identifier` as key. In case of `type=menu` it will be taken +# from the menu `title` according to Hugo's documentation and if not set +# from the menu `name` and if this is not set form the page's `linkTitle`. +# - `pageRef`, optional. In case of `type=page` this is the starting page's +# path. If not set, the home page will be used. +sidebarmenus = [ + { type = 'page', identifier = 'home', main = true, disableTitle = true, pageRef = '' }, + { type = 'menu', identifier = 'shortcuts', main = false, disableTitle = false }, +] + #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Hidden pages # These options configure how hidden pages are treated. diff --git a/exampleSite/content/authoring/frontmatter/navigationmenu/_index.en.md b/exampleSite/content/authoring/frontmatter/navigationmenu/_index.en.md index 3c5ca3a40c..d9b965d2d3 100644 --- a/exampleSite/content/authoring/frontmatter/navigationmenu/_index.en.md +++ b/exampleSite/content/authoring/frontmatter/navigationmenu/_index.en.md @@ -99,7 +99,6 @@ To stay with the [initial example](authoring/structure): Suppose you want `first For this, open `content/first-chapter/first-page/_index.md` and add the following front matter {{< multiconfig fm=true >}} -collapsibleMenu = true [_build] render = 'never' {{< /multiconfig >}} diff --git a/exampleSite/content/authoring/frontmatter/reference/frontmatter.toml b/exampleSite/content/authoring/frontmatter/reference/frontmatter.toml index 423b012fd0..f168e2f4a0 100644 --- a/exampleSite/content/authoring/frontmatter/reference/frontmatter.toml +++ b/exampleSite/content/authoring/frontmatter/reference/frontmatter.toml @@ -115,6 +115,36 @@ alwaysopen = '' # If not set, the set value of your site's hugo.toml is used. collapsibleMenu = true +# Define your own sidebar menus. +# Default: the value used below +# The sidebar menus are built from this parameter. If not set, the set value +# of your site's hugo.toml is used and contains the below default. +# Menus are written from the sidebar's top to buttom in the order given in +# this array. +# Each entry can contain the following keys: +# - `type` is mandatory. Either `page` in case it should generate a tre from +# the page structure or `menu` in case it should generate a tree from a +# defined menu. +# - `identifier` is mandatory. In case of `type=page`, anything can be used, +# in case of `type=menu` the `identifier` key must be identical to the +# key of the menu definition. +# - `main`, boolean. If `true`, the first tree level is spaced more generous +# and the text is emphasized. Default: `true` for `type=page` and `false` +# for `type=menu` +# - `disableTitle`, boolean. If `true`, there is no title above the tree. +# Default: `true` for `type=page` and `false` for `type=menu`. If a title +# should be used, in case of `type=page` it will be taken from the page's +# `menuTitle` front matter and if not set, from the translation files, using +# the menu `identifier` as key. In case of `type=menu` it will be taken +# from the menu `title` according to Hugo's documentation and if not set +# from the menu `name` and if this is not set form the page's `linkTitle`. +# - `pageRef`, optional. In case of `type=page` this is the starting page's +# path. If not set, the home page will be used. +sidebarmenus = [ + { type = 'page', identifier = 'home', main = true, disableTitle = true, pageRef = '' }, + { type = 'menu', identifier = 'shortcuts', main = false, disableTitle = false }, +] + #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Hidden pages # These options configure how hidden pages are treated. diff --git a/exampleSite/content/configuration/sidebar/shortcutmenu/_index.en.md b/exampleSite/content/configuration/sidebar/shortcutmenu/_index.en.md index dcd64d5b69..7819c1165b 100644 --- a/exampleSite/content/configuration/sidebar/shortcutmenu/_index.en.md +++ b/exampleSite/content/configuration/sidebar/shortcutmenu/_index.en.md @@ -24,7 +24,7 @@ You can disable this title with `disableShortcutsTitle=true`. To change the title, update your local i18n translation file. ````toml {title="i18n/en.toml"} -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Other Great Stuff" ```` @@ -34,31 +34,32 @@ Edit `hugo.toml` and add `[[menu.shortcuts]]` entries for each link: {{< multiconfig file=hugo >}} [[menu.shortcuts]] - name = ' GitHub Repo' - identifier = 'ds' + pre = ' ' + name = 'GitHub Repo' url = 'https://github.com/McShelby/hugo-theme-relearn' weight = 10 [[menu.shortcuts]] - name = ' Showcases' + name = 'Showcases' pageRef = '/showcase' - weight = 11 - -[[menu.shortcuts]] - name = ' Hugo Documentation' - identifier = 'hugodoc' - url = 'https://gohugo.io/' weight = 20 [[menu.shortcuts]] - name = ' Credits' + name = 'Credits' pageRef = '/more/credits' weight = 30 [[menu.shortcuts]] - name = ' Tags' + pre = ' ' + name = 'Tags' pageRef = '/tags' weight = 40 + +[[menu.shortcuts]] + pre = ' ' + name = 'Categories' + pageRef = '/categories' + weight = 50 {{< /multiconfig >}} ## Multilingual Example @@ -73,32 +74,33 @@ For multilingual sites, set different menus for each language in `hugo.toml`: languageName = 'English' [[languages.en.menu.shortcuts]] - name = ' GitHub Repo' - identifier = 'ds' + pre = ' ' + name = 'GitHub Repo' url = 'https://github.com/McShelby/hugo-theme-relearn' weight = 10 [[languages.en.menu.shortcuts]] - name = ' Showcases' + name = 'Showcases' pageRef = '/showcase' - weight = 11 - - [[languages.en.menu.shortcuts]] - name = ' Hugo Documentation' - identifier = 'hugodoc' - url = 'https://gohugo.io/' weight = 20 [[languages.en.menu.shortcuts]] - name = ' Credits' + name = 'Credits' pageRef = '/more/credits' weight = 30 [[languages.en.menu.shortcuts]] - name = ' Tags' + pre = ' ' + name = 'Tags' pageRef = '/tags' weight = 40 + [[languages.en.menu.shortcuts]] + pre = ' ' + name = 'Categories' + pageRef = '/categories' + weight = 50 + [languages.pir] title = 'Captain Hugo Relearrrn Theme' weight = 2 @@ -116,20 +118,32 @@ For multilingual sites, set different menus for each language in `hugo.toml`: weight = 11 [[languages.pir.menu.shortcuts]] - name = ' Captain Hugo Documentation' - identifier = 'hugodoc' - url = 'https://gohugo.io/' + pre = ' ' + name = 'GitHub Repo' + url = 'https://github.com/McShelby/hugo-theme-relearn' + weight = 10 + + [[languages.pir.menu.shortcuts]] + name = 'Showcases' + pageRef = '/showcase' weight = 20 [[languages.pir.menu.shortcuts]] - name = ' Crrredits' + name = 'Crrredits' pageRef = '/more/credits' weight = 30 [[languages.pir.menu.shortcuts]] - name = ' Arrr! Tags' + pre = ' ' + name = 'Arrr! Tags' pageRef = '/tags' weight = 40 + + [[languages.pir.menu.shortcuts]] + pre = ' ' + name = 'Categorrries' + pageRef = '/categories' + weight = 50 {{< /multiconfig >}} ## Displaying Pages Only in the Shortcuts Menu diff --git a/exampleSite/content/introduction/releasenotes/7/1.en.md b/exampleSite/content/introduction/releasenotes/7/1.en.md new file mode 100644 index 0000000000..08856b27f5 --- /dev/null +++ b/exampleSite/content/introduction/releasenotes/7/1.en.md @@ -0,0 +1,25 @@ ++++ +disableToc = false +hidden = true +title = "Version 7.1" +type = "releasenotes" +weight = -1 ++++ + +## 7.1.0 (xxxx-xx-xx) {#7-1-0} + +### Change + +- {{% badge style="note" title=" " %}}Change{{% /badge %}} The sidebar menus are now completely configurable. + + This is provided by the new parameter `sidebarmenus`. With the new system, you can + + - show arbitrary amounts of menus + - set headings for each menu + - base it on your page structure or use Hugo's menu feature + - configure a starting page if a menu is based on page structure + - display unlimited nesting for both menu types + - reconfigure the menus in a page's front matter + - apply the usual parameter `alwaysopen`, `collapsibleMenu`, etc. for all menu types + + You don't need to change anything in your existing installation as the old configuration is used as a default. diff --git a/exampleSite/content/more/credits/_index.en.md b/exampleSite/content/more/credits/_index.en.md index f656c87af9..7badc45d3d 100644 --- a/exampleSite/content/more/credits/_index.en.md +++ b/exampleSite/content/more/credits/_index.en.md @@ -1,5 +1,8 @@ +++ +menuPre = " " title = "Credits" +[_build] + list = "never" +++ ## Contributors diff --git a/exampleSite/content/more/credits/_index.pir.md b/exampleSite/content/more/credits/_index.pir.md index db444ced85..3cd0563d6a 100644 --- a/exampleSite/content/more/credits/_index.pir.md +++ b/exampleSite/content/more/credits/_index.pir.md @@ -1,4 +1,7 @@ +++ +menuPre = " " title = "Crrredits" +[_build] + list = "never" +++ {{< piratify >}} \ No newline at end of file diff --git a/exampleSite/content/showcase/_index.en.md b/exampleSite/content/showcase/_index.en.md index 7c68dfea09..62633f70c6 100644 --- a/exampleSite/content/showcase/_index.en.md +++ b/exampleSite/content/showcase/_index.en.md @@ -1,4 +1,5 @@ +++ +menuPre = " " title = "Showcase" [_build] render = "always" diff --git a/exampleSite/content/showcase/_index.pir.md b/exampleSite/content/showcase/_index.pir.md index 4923652ba9..3c7712542d 100644 --- a/exampleSite/content/showcase/_index.pir.md +++ b/exampleSite/content/showcase/_index.pir.md @@ -1,4 +1,5 @@ +++ +menuPre = " " title = "Showcase" [_build] render = "always" diff --git a/exampleSite/i18n/art-x-pir.toml b/exampleSite/i18n/art-x-pir.toml index 228f926b7a..02dcb4adb1 100644 --- a/exampleSite/i18n/art-x-pir.toml +++ b/exampleSite/i18n/art-x-pir.toml @@ -46,7 +46,7 @@ other = "Prrrint whole chapterrr" [More-action] other = "Morrre" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Morrre" [Expand-title] diff --git a/i18n/ar.toml b/i18n/ar.toml index c5aa8622c8..4a49761e93 100644 --- a/i18n/ar.toml +++ b/i18n/ar.toml @@ -46,7 +46,7 @@ other = "طباعة الفصل بأكمله" [More-action] other = "المزيد" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "المزيد" [Expand-title] diff --git a/i18n/cs.toml b/i18n/cs.toml index 6c2febf149..8f36ac7462 100644 --- a/i18n/cs.toml +++ b/i18n/cs.toml @@ -46,7 +46,7 @@ other = "Vytisknout kapitolu" [More-action] other = "Více" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Více" [Expand-title] diff --git a/i18n/de.toml b/i18n/de.toml index 9cfc46808e..e9d25a92ed 100644 --- a/i18n/de.toml +++ b/i18n/de.toml @@ -46,7 +46,7 @@ other = "Ganzes Kapitel drucken" [More-action] other = "Mehr" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Mehr" [Expand-title] diff --git a/i18n/en.toml b/i18n/en.toml index 1cf36e1e8b..e8c3f9daa0 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -46,7 +46,7 @@ other = "Print whole chapter" [More-action] other = "More" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "More" [Expand-title] diff --git a/i18n/es.toml b/i18n/es.toml index 6812d34190..1b386ac770 100644 --- a/i18n/es.toml +++ b/i18n/es.toml @@ -46,7 +46,7 @@ other = "Imprimir todo el capítulo" [More-action] other = "Más" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Más" [Expand-title] diff --git a/i18n/fi.toml b/i18n/fi.toml index f6ffca2bef..9af8c8a385 100644 --- a/i18n/fi.toml +++ b/i18n/fi.toml @@ -46,7 +46,7 @@ other = "Tulosta koko luku" [More-action] other = "Lisää" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Lisää" [Expand-title] diff --git a/i18n/fr.toml b/i18n/fr.toml index 19b418b67b..a206d668f9 100644 --- a/i18n/fr.toml +++ b/i18n/fr.toml @@ -46,7 +46,7 @@ other = "Imprimer le chapitre entier" [More-action] other = "Aller plus loin" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Aller plus loin" [Expand-title] diff --git a/i18n/hi.toml b/i18n/hi.toml index fe2173ca98..0dcb048a7c 100644 --- a/i18n/hi.toml +++ b/i18n/hi.toml @@ -46,7 +46,7 @@ other = "पूरा अध्याय मुद्रित करें" [More-action] other = "अधिक सामग्री दिखाएं" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "अधिक सामग्री दिखाएं" [Expand-title] diff --git a/i18n/hu.toml b/i18n/hu.toml index 1463a724fd..d1b83747a2 100644 --- a/i18n/hu.toml +++ b/i18n/hu.toml @@ -46,7 +46,7 @@ other = "Teljes fejezet nyomtatása" [More-action] other = "Egyebek" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Egyebek" [Expand-title] diff --git a/i18n/id.toml b/i18n/id.toml index 406a93b466..fb99fb8c50 100644 --- a/i18n/id.toml +++ b/i18n/id.toml @@ -46,7 +46,7 @@ other = "Mencetak seluruh bab" [More-action] other = "Lainnya" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Lainnya" [Expand-title] diff --git a/i18n/it.toml b/i18n/it.toml index bc2cb8198e..3615ece0de 100644 --- a/i18n/it.toml +++ b/i18n/it.toml @@ -46,7 +46,7 @@ other = "Stampa l'intero capitolo" [More-action] other = "Altro" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Altro" [Expand-title] diff --git a/i18n/ja.toml b/i18n/ja.toml index 6d1d251ee8..234668efef 100644 --- a/i18n/ja.toml +++ b/i18n/ja.toml @@ -46,7 +46,7 @@ other = "章全体を印刷する" [More-action] other = "更に" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "更に" [Expand-title] diff --git a/i18n/ko.toml b/i18n/ko.toml index 332060d807..c0696641dc 100644 --- a/i18n/ko.toml +++ b/i18n/ko.toml @@ -46,7 +46,7 @@ other = "전체 장 인쇄" [More-action] other = "외부 링크" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "외부 링크" [Expand-title] diff --git a/i18n/nl.toml b/i18n/nl.toml index c8d5344995..57fc6a866e 100644 --- a/i18n/nl.toml +++ b/i18n/nl.toml @@ -46,7 +46,7 @@ other = "Het hele hoofdstuk afdrukken" [More-action] other = "Snelkoppelingen" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Snelkoppelingen" [Expand-title] diff --git a/i18n/pl.toml b/i18n/pl.toml index bfdc7af750..36417a06ac 100644 --- a/i18n/pl.toml +++ b/i18n/pl.toml @@ -46,7 +46,7 @@ other = "Drukowanie całego rozdziału" [More-action] other = "Więcej" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Więcej" [Expand-title] diff --git a/i18n/pt.toml b/i18n/pt.toml index 812be0b40d..01bb30a027 100644 --- a/i18n/pt.toml +++ b/i18n/pt.toml @@ -46,7 +46,7 @@ other = "Imprimir capítulo inteiro" [More-action] other = "Mais" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Mais" [Expand-title] diff --git a/i18n/ro.toml b/i18n/ro.toml index e0920d2640..89d5e85f9f 100644 --- a/i18n/ro.toml +++ b/i18n/ro.toml @@ -46,7 +46,7 @@ other = "Tipărește întregul capitol" [More-action] other = "Mai mult" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Mai mult" [Expand-title] diff --git a/i18n/ru.toml b/i18n/ru.toml index b22111ad7c..680ebb8e56 100644 --- a/i18n/ru.toml +++ b/i18n/ru.toml @@ -46,7 +46,7 @@ other = "Печать всей главы" [More-action] other = "Еще" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Еще" [Expand-title] diff --git a/i18n/sw.toml b/i18n/sw.toml index 5b83e32f76..a804bbea0d 100644 --- a/i18n/sw.toml +++ b/i18n/sw.toml @@ -46,7 +46,7 @@ other = "Chapisha sura nzima" [More-action] other = "Zaidi" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Zaidi" [Expand-title] diff --git a/i18n/tr.toml b/i18n/tr.toml index 7cac9f25b7..2ec30e05c9 100644 --- a/i18n/tr.toml +++ b/i18n/tr.toml @@ -46,7 +46,7 @@ other = "Bölümün tamamını yazdır" [More-action] other = "Dahası Var" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Dahası Var" [Expand-title] diff --git a/i18n/vi.toml b/i18n/vi.toml index 3767751fa8..752db6f051 100644 --- a/i18n/vi.toml +++ b/i18n/vi.toml @@ -46,7 +46,7 @@ other = "In toàn bộ chương" [More-action] other = "Nội dung khác" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "Nội dung khác" [Expand-title] diff --git a/i18n/zh-CN.toml b/i18n/zh-CN.toml index 513a553070..71f3b38468 100644 --- a/i18n/zh-CN.toml +++ b/i18n/zh-CN.toml @@ -46,7 +46,7 @@ other = "打印整章" [More-action] other = "更多" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "更多" [Expand-title] diff --git a/i18n/zh-Hans.toml b/i18n/zh-Hans.toml index 513a553070..71f3b38468 100644 --- a/i18n/zh-Hans.toml +++ b/i18n/zh-Hans.toml @@ -46,7 +46,7 @@ other = "打印整章" [More-action] other = "更多" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "更多" [Expand-title] diff --git a/i18n/zh-Hant.toml b/i18n/zh-Hant.toml index 64e044bc44..8063e3c1a1 100644 --- a/i18n/zh-Hant.toml +++ b/i18n/zh-Hant.toml @@ -46,7 +46,7 @@ other = "列印整章" [More-action] other = "更多" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "更多" [Expand-title] diff --git a/i18n/zh-TW.toml b/i18n/zh-TW.toml index 64e044bc44..8063e3c1a1 100644 --- a/i18n/zh-TW.toml +++ b/i18n/zh-TW.toml @@ -46,7 +46,7 @@ other = "列印整章" [More-action] other = "更多" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "更多" [Expand-title] diff --git a/i18n/zh.toml b/i18n/zh.toml index 513a553070..71f3b38468 100644 --- a/i18n/zh.toml +++ b/i18n/zh.toml @@ -46,7 +46,7 @@ other = "打印整章" [More-action] other = "更多" -[Shortcuts-Title] +[shortcuts-menuTitle] other = "更多" [Expand-title] diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index bdc1bbd9c2..6ecbce002b 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -20,39 +20,19 @@
-
-
    - {{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .Site.Home) .Site.Home.Path }} - {{- $defaultAlwaysopen := .Site.Params.alwaysopen | default false }} - {{- range $pages }} - {{- $isSubSelf := eq . $currentNode }} - {{- $isSubAncestor := and (not $isSubSelf) (.IsAncestor $currentNode) }} - {{- $isSubHidden := or (.Params.hidden) (eq .Title "") }} - {{- if or $isSubSelf $isSubAncestor }} - {{- partial "partials/inline/menu-walker" (dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen "isSelf" $isSubSelf "isAncestor" $isSubAncestor "isHidden" $isSubHidden ) }} - {{- else if and (not $isSubHidden) (or .Params.collapsibleMenu .Site.Params.collapsibleMenu (not .Parent.RelPermalink) (eq .Parent $currentNode) (.Parent.IsAncestor $currentNode)) }} - {{- partialCached "partials/inline/menu-walker" (dict "sect" . "currentnode" $currentNode "showvisitedlinks" $showvisitedlinks "alwaysopen" $defaultAlwaysopen "isSelf" $isSubSelf "isAncestor" $isSubAncestor "isHidden" $isSubHidden) .Path }} - {{- end }} - {{- end }} -
-
- {{- $page := . }} - {{- $disableShortcutsTitle := .Site.Params.DisableShortcutsTitle }} - {{- with .Site.Menus.shortcuts }} -
- -
    - {{- range sort . "Weight" }} - {{- $shortcut := . }} - {{- with $page.Site.GetPage (printf "%s" $shortcut.URL ) }} - {{- $to := . }} -
  • {{ $shortcut.Pre }}{{ safeHTML $shortcut.Name }}{{ $shortcut.Post }}
  • - {{- else }} -
  • {{ $shortcut.Pre }}{{ safeHTML $shortcut.Name }}{{ $shortcut.Post }}
  • - {{- end }} - {{- end }} -
-
+ {{- $menuconfigs := .Params.sidebarmenus | default site.Params.sidebarmenus | default (slice + (dict "type" "page" "identifier" "home") + (dict "type" "menu" "identifier" "shortcuts") + ) }} + {{- range $menuconfigs }} + {{- $config := . }} + {{- if eq $config.type "page" }} + {{- partial "partials/inline/page-tree" (dict "currentnode" $currentNode "config" $config "showvisitedlinks" $showvisitedlinks) }} + {{- else if eq $config.type "menu" }} + {{- partial "partials/inline/menu-tree" (dict "currentnode" $currentNode "config" $config "showvisitedlinks" $showvisitedlinks) }} + {{- else }} + {{- warnf "WARNING: unknown menu type '%s' found in parameter 'sidebarmenus' for menu '%s'; use either 'page' or 'menu'" $config.type $config.identifier }} + {{- end }} {{- end }} {{- $siteLanguages := .Site.Languages }} {{- $showlangswitch := and hugo.IsMultilingual (not .Site.Params.disableLanguageSwitchingButton) (gt (int (len $siteLanguages)) 1) }} @@ -119,19 +99,58 @@
-{{- define "partials/inline/menu-walker" }} +{{- define "partials/inline/page-tree" }} + {{- $currentNode := .currentnode }} + {{- $config := .config }} + {{- $showvisitedlinks := .showvisitedlinks }} +
+ {{- with site.Home.GetPage ($config.pageRef | default "") }} + {{- $entry := . }} + {{- $entries := partialCached "_relearn/pages.gotmpl" (dict "page" $entry) $entry.Path }} + {{- $title := "" }} + {{- if not ($config.disableTitle | default true) }} + {{ $title = $entry.Params.menuTitle | default (T (print $config.identifier "-menuTitle")) }} + {{- end }} + {{- with $title }} + + {{- end }} + {{- $classes := "space " }} + {{- if ($config.main | default true) }} + {{- $classes = "enlarge morespace " }} + {{- end }} + +
+ {{- else }} + {{- warnf "WARNING: page '%s' not found for sidebar menu '%s'" ($config.pageRef | default "") $config.identifier }} + {{- end }} +{{- end }} +{{- define "partials/inline/page-walker" }} {{- $currentNode := .currentnode }} {{- $showvisitedlinks := .showvisitedlinks }} {{- $alwaysopen := .alwaysopen }} - {{- $currentFileRelPermalink := .currentnode.RelPermalink }} {{- $isSelf := .isSelf }} {{- $isAncestor := .isAncestor }} {{- $isHidden := .isHidden }} {{- with .sect }} {{- $isActive := $isSelf }} - {{- $pages := partialCached "_relearn/pages.gotmpl" (dict "page" .) .Path }} + {{- $entry := . }} + {{- $entries := partialCached "_relearn/pages.gotmpl" (dict "page" .) .Path }} {{- $hasVisibleChildren := false }} - {{- range $pages }} + {{- range $entries }} {{- $isSubSelf := eq . $currentNode }} {{- $isSubAncestor := and (not $isSubSelf) (.IsAncestor $currentNode) }} {{- $isSubHidden := or (.Params.hidden) (eq .Title "") }} @@ -142,31 +161,164 @@ {{- end }} {{- $title := partial "title.gotmpl" (dict "page" . "linkTitle" true) }} {{- $url := partial "permalink.gotmpl" (dict "to" .) }} + {{- $pre := partial "menu-pre.html" . }} + {{- $post := partial "menu-post.html" . }} {{- if $hasVisibleChildren }} - {{- $isCollapsible := or .Params.collapsibleMenu .Site.Params.collapsibleMenu }} + {{- $isCollapsible := .Params.collapsibleMenu | default site.Params.collapsibleMenu }} {{- $currentAlwaysopen := .Params.alwaysopen | default $alwaysopen }} - {{- $pageId := md5 .Page }} + {{- if and (not $url) (not $isCollapsible) }} + {{- $currentAlwaysopen = true }} + {{- end }} + {{- $entryId := md5 .Path }} {{- $isOpen := or $currentAlwaysopen $isSelf $isAncestor }}
  • - {{- if $isCollapsible }}{{ end }} + {{- if $isCollapsible }}{{ end }} {{- if $url }}{{ else }}{{ end }} - {{- partial "menu-pre.html" . }}{{ $title }}{{ partial "menu-post.html" . }} - {{- if $url }}{{ if $showvisitedlinks }}{{ end }}{{ else }}{{ end }}