Is it possible to inject/add front matter key/values using a hook for newly created markdown files (posts or custom collections)?
I am aware of the ability to add default header values using defaults in _config.yml file. However, this does not add those values to the actual front matter header and only allows access in liquid on the page variable.
The reason for this is because we have our pages structured like _pages/category/sub-category/file.md and we use cloud cannon for non technical users to edit/create content.
I’ve got a proof of concept working using File.write() within a hook but this triggers an infinite regenerate loop when running jekyll serve (I believe its because the file is written and the hook is triggered creating a loop).
I am using Jekyll::Hooks.register :site, :post_read to achieve this. Can someone give me advice on how to accomplish this? Ultimately, we want a hook to run for newly created files and do some logic to add the yaml front matter headers for the file.
Yeah we’re already using cloud cannon defaults feature but the issue is when we have nested folders within a collection. Cloud cannon only allows one defaults.md for a collection so you cannot nest it like so: _pages/category/sub-category/_defaults.md, it will only work when you have it within root of the collection folder _pages/category/_defaults.md.
We’re looking for a way to categorize “pages” similar to how posts is done out of the box in Jekyll but without the need to make the filename in the date-title.md format. We’re also using posts but its for blogs/news related articles that require date and other blog related attributes.
Make sure you specify which collections to dynamically add category/sub category to their front matter headers in _data/categorize_collections.yml or it defaults to pages collection.