Since it seems to not be possible to include a Content File (or any other, for what matters) into another natively and I would really like such feature to have some sort of composite content, I’ trying to develop a shortcode for that but I stumbled in one problem.
The contents read with readFile, as expected with a raw data read, also comes with the unparsed FrontMatter. I tried to remove it with replaceRE but it seems that Go/Hugo is too much different or poorly implemented for this matter.
I tried the most simple and generic regex I could think:
I also tried to split the readFile part from the replaceRE with a variable, tried to use the “non-piped” way for the function and even escaping the dash thinking it could be some sort of special character (even though it shouldn’t) without success.
What the heck should I do to remove this piece of data before I can apply markdownify on it?
I believe that is exactly what page bundles were created for. You might consider putting the files you want to read into a bundle of text files without front matter, and call the specific resource via shortcode.
As far as I could understand, I’m looking for headless bundles, but I’ve added the headless: true to the leaf that would be included and tried {{ .Site.GetPage "page" (.Get "file") }} in the include shortcode I made and I received Page("Included Page Title")
I suppose it has something to do with the second argument “page” that wasn’t very clear for a change.
Does this function stripes off the FrontMatter, leaving only the content? If so, that would solve the issue, yes, but would cause a smaller one, preventing an idea I had of saving a copy of the plugged Content File’s FrontMatter in a variable.
Well, I finally had some time to get back to that Shortcode and it worked, that GetPage was precisely what I was looking for. I just had to remove the .Summary from the .Content to make Content Files really plugable.
This does work in case you dont want to do any further processing on the file after it has been read an included. This has issues if you are going to further process the markdown in any way.
My usecase was to do an include of an markdown file and then do a custom _default/_markup/render_image.html on all valid markdown files. When I tried to do that with above my render_image.html generated HTML appeared as “text” rather than an actual image link. I tried a lot of combinations but it didnt seem to work.
What worked finally was having the readfile shortcode do: