How can I serve a static file with frontmatter?

I want to serve a file that contains frontmatter in a Jekyll powered site. I want the HTTP response to include the YAML frontmatter. As far as I can tell, Jekyll will always remove it which is unacceptable for my usecase. As a temporarily workaround, as this site is hosted on Github Pages from a public repo, I’m using the raw.githubusercontent.com to load it directly from github.

Context: these files are queries for Ultra which, like Jekyll, uses YAML frontmatter for configuration.

If jekyll processes it I think it will remove any front matter - no way to stop it that I know of - so you need something else to maintain those files maybe? one way is you can tell jekyll to not nuke a folder in the _site directory though that is hard to manage other than locally - and even then prone to error.

You could have something else copy the files into the _site folder for - like gulp or npm, some sort of build process that could run after jekyll.

Your work around might be the simplest though.

Does the Ulta thing allow other delimiters besides the 3 dashes? I think some things allow other things like 3 ~'s?

ah - maybe I am thinking it is 3 dashes - but yaml is different, hopefully that is the answer!

One workaround is to use raw to quote the file contents. This will produce the correct output:

---
---
{% raw %}---
type: overpass
....
out geom;{% endraw %}

1 Like

I found jekyll-include-raw | Jekyll Themes which gets me a similar approach to your suggestion @chuckhoupt. Haven’t actually decided if it’s worth it, but it’s an option.

If you’re able to use 3rd party plugins, then there may be plugins for copying files unmodified. For example (I haven’t tested it):

1 Like

That worked like a charm @chuckhoupt! Thank you. https://github.com/MapRVA/maprva.org/commit/76eb1cd1bc8c022399f578e38f89917b98c97056

1 Like