From 7c5586abab1dbd586be320210ee9423da72e6bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Fri, 7 Oct 2022 22:02:48 +0200 Subject: [PATCH] print: fix links of subsections #340 --- layouts/partials/nested-article.hugo | 3 +++ 1 file changed, 3 insertions(+) diff --git a/layouts/partials/nested-article.hugo b/layouts/partials/nested-article.hugo index 7ad35ab132..73b9111147 100644 --- a/layouts/partials/nested-article.hugo +++ b/layouts/partials/nested-article.hugo @@ -94,7 +94,10 @@ {{- $currentNode := .currentnode }} {{- with .sect }} {{- $page := . }} + {{/* if we have a relative link in a print page, our print URL is one level to deep; so we are making it absolute to our page by prepending the page's permalink */}} + {{- $link_prefix := strings.TrimRight "/" .Page.RelPermalink }} {{- $content := partial "output-partial.hugo" (dict "base" "content" "page" . "parameter" $page) }} + {{- $content = replaceRE "((?:src|href)\\s*=(?:\\s*[\"']\\s*)?)(\\.[^\"'\\s>]*|[\\w]+[^\"'\\s>:]*)([\"'\\s>])" (printf "${1}%s/${2}${3}" $link_prefix) $content }} {{- partial "output-partial.hugo" (dict "base" "article" "page" $page "parameter" (dict "page" $page "content" $content)) }} {{- $currentNode.Page.Store.Set "nestedHasMathJax" (or ($currentNode.Page.Store.Get "nestedHasMathJax") (.Page.Store.Get "hasMathJax")) }} {{- $currentNode.Page.Store.Set "nestedHasMermaid" (or ($currentNode.Page.Store.Get "nestedHasMermaid") (.Page.Store.Get "hasMermaid")) }}