diff --git a/exampleSite/config/_default/config.toml b/exampleSite/config/_default/config.toml index ff51da416d..a15c6edcd8 100644 --- a/exampleSite/config/_default/config.toml +++ b/exampleSite/config/_default/config.toml @@ -215,6 +215,7 @@ title = "Hugo Relearn Documentation" showVisitedLinks = true collapsibleMenu = true disableBreadcrumb = false + disableRootBreadcrumb = true disableInlineCopyToClipBoard = true disableNextPrev = false disableLandingPageButton = true diff --git a/exampleSite/content/basics/configuration/_index.en.md b/exampleSite/content/basics/configuration/_index.en.md index d19cbedae5..afe44d5e65 100644 --- a/exampleSite/content/basics/configuration/_index.en.md +++ b/exampleSite/content/basics/configuration/_index.en.md @@ -53,6 +53,8 @@ Note that some of these parameters are explained in details in other sections of disableLanguageSwitchingButton = false # Hide breadcrumbs in the header and only show the current page title disableBreadcrumb = true + # Hide the root (first) breadcrumb in the header + disableRootBreadcrumb = true # If set to true, hide table of contents menu in the header of all pages disableToc = false # If set to false, load the MathJax module on every page regardless if a MathJax shortcode is present diff --git a/exampleSite/content/basics/migration/_index.en.md b/exampleSite/content/basics/migration/_index.en.md index 2a1c3594ce..a38b596779 100644 --- a/exampleSite/content/basics/migration/_index.en.md +++ b/exampleSite/content/basics/migration/_index.en.md @@ -32,7 +32,11 @@ This document shows you what's new in the latest release. For a detailed list of In this case it is advised to remove the `title` from the headless branch parent's frontmatter, as it will otherwise appear in your breadcrumbs. -- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The above change has a nice side effect. It is now possible to overwrite the setting for `collapsibleMenu` of your `config.toml` inside of a page's frontmatter. +- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} It is now possible to overwrite the setting for `collapsibleMenu` of your `config.toml` inside of a page's frontmatter. + +- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} It is now possible to remove the root breadcrumb by setting `disableRootBreadcrumb=true` in your `config.toml`. + +- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The output of the dedicated search page now displays the result's breadcrumb. --- diff --git a/layouts/_default/index.json b/layouts/_default/index.json index f0c5ea4ff2..abd89e5696 100644 --- a/layouts/_default/index.json +++ b/layouts/_default/index.json @@ -15,7 +15,14 @@ {{- end }} {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) .Title }} {{- end }} - {{- $pages = $pages | append (dict "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) "title" $title "tags" .Params.tags "description" .Description "content" (.Plain | htmlUnescape)) }} + {{- $pages = $pages | append (dict + "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) + "title" $title + "tags" .Params.tags + "breadcrumb" (trim ((partial "breadcrumbs.html" (dict "page" . "dirOnly" true)) | plainify | htmlUnescape) "\n\r\t ") + "description" .Description + "content" (.Plain | htmlUnescape) + ) }} {{- end }} {{- end -}} {{- $pages | jsonify (dict "indent" " ") }} diff --git a/layouts/_default/index.search.js b/layouts/_default/index.search.js index 4e98237b5c..aaea2ab9dd 100644 --- a/layouts/_default/index.search.js +++ b/layouts/_default/index.search.js @@ -15,7 +15,14 @@ {{- end }} {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) .Title }} {{- end }} - {{- $pages = $pages | append (dict "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) "title" $title "tags" .Params.tags "description" .Description "content" (.Plain | htmlUnescape)) }} + {{- $pages = $pages | append (dict + "uri" (partial "relLangPrettyUglyURL.hugo" (dict "to" .)) + "title" $title + "tags" .Params.tags + "breadcrumb" (trim ((partial "breadcrumbs.html" (dict "page" . "dirOnly" true)) | plainify | htmlUnescape) "\n\r\t ") + "description" .Description + "content" (.Plain | htmlUnescape) + ) }} {{- end }} {{- end -}} var relearn_search_index = {{ $pages | jsonify (dict "indent" " ") }} diff --git a/layouts/partials/breadcrumbs.html b/layouts/partials/breadcrumbs.html new file mode 100644 index 0000000000..a1cb093266 --- /dev/null +++ b/layouts/partials/breadcrumbs.html @@ -0,0 +1,54 @@ +{{- $page := .page }} +{{- $to := $page }} +{{- $pageurl := partial "relLangPrettyUglyURL.hugo" (dict "to" $page) }} +{{- $lasturl := partial "relLangPrettyUglyURL.hugo" (dict "to" $page) }} +{{- if .dirOnly }} + {{- $page = $page.Parent }} + {{- $to = $page }} + {{- $lasturl = partial "relLangPrettyUglyURL.hugo" (dict "to" $page) }} +{{- end }} +{{- $depth := add 1 (int (partial "get-page-depth.hugo" (dict "page" $page))) }} +{{- if .page.Site.Params.disableRootBreadcrumb }} + {{- $depth = add $depth -1 }} +{{- end }} +{{- $breadcrumb := slice }} +{{- range seq $depth }} + {{- if $to }} + {{- if $to.Title }} + {{- $breadcrumb = $breadcrumb | append $to }} + {{- end }} + {{- else }} + {{- break }} + {{- end }} + {{- $to = $to.Parent }} +{{- end }} +{{- $len := len $breadcrumb -}} +{{- $breadcrumbReversed := slice }} +{{- range seq $len }} + {{- $breadcrumbReversed = $breadcrumbReversed | append (index $breadcrumb (sub $len .)) }} +{{- end }} +{{- range $i, $e := $breadcrumbReversed }} + {{- $to := $e }} + {{- $title := $to.Title }} + {{- if eq .Kind "taxonomy" }} + {{- $title = i18n $to.Data.Plural }} + {{- if not $title }} + {{- $title = $to.Data.Plural }} + {{- end }} + {{- else if eq .Kind "term" }} + {{- $title = i18n $to.Data.Singular }} + {{- if not $title }} + {{- $title = $to.Data.Singular }} + {{- end }} + {{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) $to.Title }} + {{- end }} + {{- if not $title }} + {{- $title = $to.Site.Title }} + {{- end }} + {{- $url := partial "relLangPrettyUglyURL.hugo" (dict "to" $to) }} + {{- $isPage := eq $url $pageurl }} + {{- $isLast := eq $url $lasturl }} + {{- $link := and $url (not $isPage) }} + {{- printf "