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).
This commit is contained in:
Salim B 2021-05-01 18:33:49 +02:00 committed by Bjørn Erik Pedersen
parent 04d30677dd
commit d61a580103
3 changed files with 23 additions and 2 deletions

View File

@ -204,7 +204,7 @@ aliased form `.Pages`.
### `.Pages` compared to `.Site.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 ## Page-level Params

View File

@ -127,7 +127,7 @@ You can use `.Site.Params` in a [partial template](/templates/partials/) to call
### `.Site.Pages` compared to `.Pages` ### `.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" >}}

View File

@ -0,0 +1,21 @@
<!-- {{/*
Insert page `.Content` from a (headless) bundle; you can insert `.Content` from multiple page resources of the same bundle by specifying `glob`
Usage: {{< insertpages path="PATH/TO/MD_FILE" >}}
{{< insertpages path="PATH/TO/BUNDLE" glob="*_PATTERN.md" >}}
*/}} -->
{{ $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 -}}