mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-14 14:15:51 -04:00
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:
parent
04d30677dd
commit
d61a580103
@ -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
|
||||
|
||||
|
@ -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" >}}
|
||||
|
||||
|
||||
|
||||
|
21
layouts/shortcodes/insertpages.html
Normal file
21
layouts/shortcodes/insertpages.html
Normal 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 -}}
|
Loading…
x
Reference in New Issue
Block a user