2
votes

I have a YAML file that holds some data and needs to be processed client side.

---

some: content

...

Jekyll handles everything with Front Matter, which results in the whole YAML content to be treated as Front Matter and the page then has no content.

Is there a way to tell Jekyll to treat the file as static, even though it has a YAML header?

I tried different combinations of exclude and keep_files, also setting Front Matter defaults in my _config.yml, but nothing is really working.

My workaround now is to add an additional Front Matter block in front of the content:

---
layout: null
---
---

some: content

...

The YAML file though is a swagger definition and adding this extra block would both:

  • make it complicated to test/generate the definition locally or in Swagger Editor
  • Generate confusion, if the file is downloaded via github.

So ideally I would like to store the file without any modification and somehow teach Jekyll to leave it alone.

2

2 Answers

2
votes

There is no way to tell Jekyll to avoid to process a file with front matter without a plugin.

A simple solution would be to use Jekyll hook's to copy the original unprocessed file with front matter to the generated site just after the whole site has been generated.

For example, adding _plugins/copyfile.rb:

Jekyll::Hooks.register :site, :post_write do |site|
  src = "_unprocessed/about.md"
  dest = "_site/assets"
  puts "Copying #{src} to #{dest}"
  FileUtils.cp(src, dest)
end

That would copy _unprocessed/about.md with front matter to the final site assets dir.

As _unprocessed starts with an underscore it won't be present in the resulting site.

Building the site:

/tmp/s⟫jekyll b
Configuration file: /tmp/s/_config.yml
            Source: /tmp/s
       Destination: /tmp/s/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
Copying _unprocessed/about.md to _site/assets
                    done in 0.884 seconds.
 Auto-regeneration: disabled. Use --watch to enable.


/tmp/s⟫ tree _site/
_site/
├── 404.html
├── assets
│   ├── about.md
│   └── main.css
├── feed.xml
├── index.html
└── jekyll
    └── update
        └── 2017
            └── 11
                └── 09
                    └── welcome-to-jekyll.html

6 directories, 6 files
1
votes

Cross-posting my answer here as it may be relevant (not sure; I'm not a Jekyll user but github pages uses it.) https://stackoverflow.com/a/48954668/1461007