From 0dcd241753b50c61d6d25a2e9982f20c1e4c3fe3 Mon Sep 17 00:00:00 2001 From: LorenzBischof <1837725+LorenzBischof@users.noreply.github.com> Date: Sat, 20 Apr 2024 22:48:02 +0200 Subject: [PATCH] Refactor automatic section numbers --- README.md | 5 ++-- hugo.toml | 19 ++++++++++++++- layouts/_default/content.html | 7 +----- layouts/docs/list.html | 7 +----- layouts/index.sectionnumber.html | 16 ++++++++++++ layouts/partials/section-index.html | 11 ++------- layouts/partials/sectionnumber.html | 38 +++-------------------------- layouts/partials/sidebar-tree.html | 9 ++----- layouts/pdf/list.html | 21 +++------------- layouts/shortcodes/link.html | 6 +---- layouts/shortcodes/task.html | 8 +++--- 11 files changed, 54 insertions(+), 93 deletions(-) create mode 100644 layouts/index.sectionnumber.html diff --git a/README.md b/README.md index d0dc5e1..794f213 100644 --- a/README.md +++ b/README.md @@ -172,10 +172,11 @@ When using the Mode Switcher and including a nested Read and Highlight shortcode ## Automatic Section Numbers -This feature can be enabled by adding the following configuration in the `params` section in your `config.toml` +This feature can be enabled by adding the following configuration in your `hugo.toml` ```yaml -automaticSectionNumbers = true +[outputs] + home = ['html', 'sectionnumber', 'rss'] ``` All Sections under docs will then have the section number prefixed to the title. diff --git a/hugo.toml b/hugo.toml index 406dee5..bdca8b3 100644 --- a/hugo.toml +++ b/hugo.toml @@ -1,4 +1,21 @@ +# This output format configuration is necessary +# to ensure that Hugo sets the Page.Store values +# for sectionnumbers before rendering the site. +# There is an associated layout for the homepage. +# This is a bit of a hack, but I don't know any better way. +# To activate the sectionnumbers, add the format to your outputs. +[outputFormats] + [outputFormats.sectionnumber] + mediaType = 'text/html' + notAlternative = true + weight = 1 + # Make sure that the output does not override the homepage. + # Seems to only happen locally in some cases. + basename = ".ignore" + [outputFormats.html] + weight = 2 + [module] [module.hugoVersion] extended = true @@ -8,4 +25,4 @@ disable = false [[module.imports]] path = "github.com/google/docsy/dependencies" - disable = false \ No newline at end of file + disable = false diff --git a/layouts/_default/content.html b/layouts/_default/content.html index abb48f3..485af8d 100644 --- a/layouts/_default/content.html +++ b/layouts/_default/content.html @@ -1,11 +1,6 @@ {{/* Copied and adapted from themes/docsy/layouts/_default/content.html */}}
- {{- if site.Params.automaticSectionNumbers -}} - {{- $sectionnumbers := partialCached "sectionnumber.html" . .File.Path -}} -

{{ $sectionnumbers.Get .File.Path }} {{ .Title }}

- {{- else -}} -

{{ .Title }}

- {{- end -}} +

{{ partial "sectionnumber" . }}{{ .Title }}

{{ with .Params.description }}
{{ . | markdownify }}
{{ end }}
{{ partial "taxonomy_terms_article_wrapper.html" . -}} diff --git a/layouts/docs/list.html b/layouts/docs/list.html index b71024f..eca99e8 100644 --- a/layouts/docs/list.html +++ b/layouts/docs/list.html @@ -1,11 +1,6 @@ {{ define "main" }}
- {{- if site.Params.automaticSectionNumbers -}} - {{- $sectionnumbers := partialCached "sectionnumber.html" . .File.Path -}} -

{{ $sectionnumbers.Get .File.Path }} {{ .Title }}

- {{- else -}} -

{{ .Title }}

- {{- end -}} +

{{ partial "sectionnumber" . }}{{ .Title }}

{{ with .Params.description }}
{{ . | markdownify }}
{{ end }}