Hi, I am using the Wowchemy theme for Hugo, which uses a block based approach to construct the single pages. This means that everything is declared in the page Front Matter, and not in the Content.
I have a problem with the shortcodes in the front matter: they cannot access the correct .Page
variable (which for instance I need to construct relative paths).
I did some tests, with this content structures:
content
├── _index.md # homepage
├── post/writing-technical-content/ # post example
│ ├── results.csv
│ └── index.md
└── csv/ # leaf boundle
├── index.md
└── data.csv
Using the shortcode in the csv/index.md
, I get:
- Shortcode in the Front Matter
= &hugolib.ShortcodeWithPage{Params:[]string(nil), Inner:"", Page:(*hugolib.pageForShortcode)(0xc004c68800), Parent:(*hugolib.ShortcodeWithPage)(nil), Name:"page_info", IsNamedParams:false, Ordinal:0, indentation:"", innerDeindentInit:sync.Once{done:0x0, m:sync.Mutex{state:0, sema:0x0}}, innerDeindent:"", posInit:sync.Once{done:0x0, m:sync.Mutex{state:0, sema:0x0}}, posOffset:45, pos:text.Position{Filename:"", Offset:0, LineNumber:0, ColumnNumber:0}, scratch:(*maps.Scratch)(nil)}
.Page = &{Page(/_index.md) nopPage 0xc0013b8270}
.Page.Parent = <nil>
.Page.BundleType = "branch"
.Page.File.Dir = "/"
.Page.RelPermalink = /
- Shortcode in the page Content:
. = &hugolib.ShortcodeWithPage{Params:[]string(nil), Inner:"", Page:(*hugolib.pageForShortcode)(0xc0087f7240), Parent:(*hugolib.ShortcodeWithPage)(nil), Name:"page_info", IsNamedParams:false, Ordinal:0, indentation:"", innerDeindentInit:sync.Once{done:0x0, m:sync.Mutex{state:0, sema:0x0}}, innerDeindent:"", posInit:sync.Once{done:0x0, m:sync.Mutex{state:0, sema:0x0}}, posOffset:228, pos:text.Position{Filename:"", Offset:0, LineNumber:0, ColumnNumber:0}, scratch:(*maps.Scratch)(nil)}
.Page = &{Page(/csv/index.md) nopPage 0xc004921770}
.Page.Parent = Page(/_index.md)
.Page.BundleType = "leaf"
.Page.File.Dir = "csv/"
.Page.RelPermalink = /csv/
You can see that in the first case Hugo is not able to determine the correct path (csv/
), but instead it returns the root /
.
You can find the original issue here in the Wowchemy github, but I think this could actually be an error in Hugo.
You can also clone this branch to get a minimal example (run hugo server
and then navigate to /csv/
page).
Thank you for your support!