Files
hugo/layouts/shortcodes/insertpages.html
T
Salim B d61a580103 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).
2021-05-03 21:08:23 +02:00

22 lines
747 B
HTML

<!-- {{/*
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 -}}