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 }}