From d61a5801033615fffa943eecbdcf2a55ce2fc0c4 Mon Sep 17 00:00:00 2001 From: Salim B Date: Sat, 1 May 2021 18:33:49 +0200 Subject: [PATCH] Add `insertpages` shortcode This is an improvement over the `readfiles` shortcode in that it allows to insert content files that contain shortcodes themselves. This new shortcode is used to fix a regression introduced in https://github.com/gohugoio/hugoDocs/pull/1442 (`new-in` shortcode was not rendered as intended). --- content/en/variables/page.md | 2 +- content/en/variables/site.md | 2 +- layouts/shortcodes/insertpages.html | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 layouts/shortcodes/insertpages.html diff --git a/content/en/variables/page.md b/content/en/variables/page.md index cbdd5b6e3..c98e2586c 100644 --- a/content/en/variables/page.md +++ b/content/en/variables/page.md @@ -204,7 +204,7 @@ aliased form `.Pages`. ### `.Pages` compared to `.Site.Pages` -{{< readfile file="/content/en/readfiles/pages-vs-site-pages.md" markdown="true" >}} +{{< insertpages path="readfiles/pages-vs-site-pages.md" >}} ## Page-level Params diff --git a/content/en/variables/site.md b/content/en/variables/site.md index e5d2e52f9..0bf54a7fa 100644 --- a/content/en/variables/site.md +++ b/content/en/variables/site.md @@ -127,7 +127,7 @@ You can use `.Site.Params` in a [partial template](/templates/partials/) to call ### `.Site.Pages` compared to `.Pages` -{{< readfile file="/content/en/readfiles/pages-vs-site-pages.md" markdown="true" >}} +{{< insertpages path="readfiles/pages-vs-site-pages.md" >}} diff --git a/layouts/shortcodes/insertpages.html b/layouts/shortcodes/insertpages.html new file mode 100644 index 000000000..74f726db1 --- /dev/null +++ b/layouts/shortcodes/insertpages.html @@ -0,0 +1,21 @@ + +{{ $path := .Get "path" -}} +{{ $glob := .Get "glob" -}} + +{{ $scratch := newScratch -}} +{{ with $glob -}} + {{ $bundle := site.GetPage (path.Join $path "index.md") -}} + {{ $scratch.Set "pages" ($bundle.Resources.Match $glob) -}} +{{ else -}} + {{ $bundle := site.GetPage (path.Join (path.Dir $path) "index.md") -}} + {{ $scratch.Set "pages" ($bundle.Resources.Match (path.Base $path)) -}} +{{ end -}} + +{{ range ($scratch.Get "pages") -}} + {{ .Content }} +{{ end -}}