From c9f809ca19aa85dfca0a518e278128832eb3b864 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Tue, 15 Feb 2022 20:58:35 +0100 Subject: [PATCH] fix: fix edit page link and auto-detect contentDir (#343) BREAKING CHANGE: With support of the multilingual mode, we broke the `edit page` links, as the content directory was statically hard-coded into the `GeekdocEditPath` parameter. To get the correct content directory, regardless of the language or a disabled multilingual mode, we now use Hugo's built-in `.Site.Params.contentDir` parameter. Therefor, you have to remove the hard-coded `/content` part from the `geekdocEditPath` parameter in the configuration of your project. --- .gitignore | 3 +++ exampleSite/config/_default/params.yaml | 2 +- exampleSite/content/en/usage/configuration.md | 26 +++++++++---------- layouts/partials/page-header.html | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 470fb8c..2042e76 100644 --- a/.gitignore +++ b/.gitignore @@ -21,5 +21,8 @@ exampleSite/content/de /exampleSite/resources/ /exampleSite/data/sprites/ +# hugo +.hugo_build.lock + # testing .lighthouseci/ diff --git a/exampleSite/config/_default/params.yaml b/exampleSite/config/_default/params.yaml index 8917d7c..12ca547 100644 --- a/exampleSite/config/_default/params.yaml +++ b/exampleSite/config/_default/params.yaml @@ -8,7 +8,7 @@ geekdocToC: 3 geekdocTagsToMenu: true geekdocRepo: https://github.com/thegeeklab/hugo-geekdoc -geekdocEditPath: edit/main/exampleSite/content +geekdocEditPath: edit/main/exampleSite geekdocSearch: true geekdocSearchShowParent: true diff --git a/exampleSite/content/en/usage/configuration.md b/exampleSite/content/en/usage/configuration.md index d298000..f931fee 100644 --- a/exampleSite/content/en/usage/configuration.md +++ b/exampleSite/content/en/usage/configuration.md @@ -50,7 +50,7 @@ enableRobotsTXT = true geekdocMenuBundle = true # (Optional, default false) Collapse all menu entries, can not be overwritten - # per page if enabled. Can be enabled per page via `geekdocCollapseSection`. + # per page if enabled. Can be enabled per page via 'geekdocCollapseSection'. geekdocCollapseAllSections = true # (Optional, default true) Show page navigation links at the bottom of each @@ -66,9 +66,9 @@ enableRobotsTXT = true geekdocRepo = "https://github.com/thegeeklab/hugo" # (Optional, default none) Enable 'Edit page' links. Requires 'GeekdocRepo' param - # and path must point to 'content' directory of repo. + # and the path must point to the parent directory of the 'content' folder. # You can also specify this parameter per page in front matter. - geekdocEditPath = "edit/main/exampleSite/content" + geekdocEditPath = "edit/main/exampleSite" # (Optional, default true) Enables search function with flexsearch. # Index is built on the fly and might slow down your website. @@ -163,7 +163,7 @@ params: geekdocMenuBundle: true # (Optional, default false) Collapse all menu entries, can not be overwritten - # per page if enabled. Can be enabled per page via `geekdocCollapseSection`. + # per page if enabled. Can be enabled per page via 'geekdocCollapseSection'. geekdocCollapseAllSections: true # (Optional, default true) Show page navigation links at the bottom of each @@ -178,10 +178,10 @@ params: # You can also specify this parameter per page in front matter. geekdocRepo: "https://github.com/thegeeklab/hugo-geekdoc" - # (Optional, default none) Enable "Edit page" links. Requires 'GeekdocRepo' param - # and path must point to 'content' directory of repo. + # (Optional, default none) Enable 'Edit page' links. Requires 'GeekdocRepo' param + # and the path must point to the parent directory of the 'content' folder. # You can also specify this parameter per page in front matter. - geekdocEditPath: edit/main/exampleSite/content + geekdocEditPath: edit/main/exampleSite # (Optional, default true) Enables search function with flexsearch. # Index is built on the fly and might slow down your website. @@ -262,9 +262,9 @@ geekdocBreadcrumb = false # Set source repository location. geekdocRepo = "https://github.com/thegeeklab/hugo-geekdoc" -# Enable "Edit page" links. Requires 'GeekdocRepo' param and path must point -# to 'content' directory of repo. -geekdocEditPath = "edit/main/exampleSite/content" +# Enable 'Edit page' links. Requires 'GeekdocRepo' param and the path must point to +# the parent directory of the 'content' folder. +geekdocEditPath = "edit/main/exampleSite" # Used for 'Edit page' link, set to '.File.Path' by default. # Can be overwritten by a path relative to 'geekdocEditPath' @@ -322,9 +322,9 @@ geekdocBreadcrumb: false # Set source repository location. geekdocRepo: "https://github.com/thegeeklab/hugo-geekdoc" -# Enable "Edit page" links. Requires 'GeekdocRepo' param and path must point -# to 'content' directory of repo. -geekdocEditPath: "edit/main/exampleSite/content" +# Enable 'Edit page' links. Requires 'GeekdocRepo' param and the path must point to +# the parent directory of the 'content' folder. +geekdocEditPath: "edit/main/exampleSite" # Used for 'Edit page' link, set to '.File.Path' by default. # Can be overwritten by a path relative to 'geekdocEditPath' diff --git a/layouts/partials/page-header.html b/layouts/partials/page-header.html index 9d94525..008dd04 100644 --- a/layouts/partials/page-header.html +++ b/layouts/partials/page-header.html @@ -1,7 +1,7 @@ {{ $geekdocRepo := default (default false .Site.Params.GeekdocRepo) .Page.Params.GeekdocRepo }} {{ $geekdocEditPath := default (default false .Site.Params.GeekdocEditPath) .Page.Params.GeekdocEditPath }} {{ if .File }} - {{ $.Scratch.Set "geekdocFilePath" (default .File.Path .Page.Params.GeekdocFilePath) }} + {{ $.Scratch.Set "geekdocFilePath" (default (path.Join .Site.Params.contentDir .File.Path) .Page.Params.GeekdocFilePath) }} {{ else }} {{ $.Scratch.Set "geekdocFilePath" false }} {{ end }}