Jekyll - Generating JSON Files Alongside the HTML Files

jekyll build hook to create gz versions of each .html file

There is no hook in jekyll build.
The only way to generate additional content is to write a generator plugin.

If your goal is to serve the gzipped version of you pages, you must know that github pages already serves gzipped html, css and js.

Generate json array of directory in Ruby?

You can use globs and wildcards with Ruby's Dir class. You could get an array of .html files recursively from the current directory, using something along the lines of files = Dir['./**/*.html'].

To generate JSON, you'd want to first ensure that the person using your plugin has access to a JSON library (require 'json') and then use the #to_json helper method on your files array: files.to_json

Get Jekyll Data Files inside Converter Plugin

Edit : As context.registers[:site] is not available in Converter plugins.
But you can use this dirty trick:

  def initialize(config)
dir = config['data_source']
filePath = File.join(dir, 'links.yml')
data = SafeYAML.load_file(filePath)
end

Does Jekyll process files with no front matter?

Because GitHub Pages auto-loads the jekyll-optional-front-matter package as a dependency, your markdown files without a front matter do work on your GitHub Pages hosted site.

https://github.com/benbalter/jekyll-optional-front-matter explains why:

Out of the box, Jekyll requires that any markdown file have YAML front matter (key/value pairs separated by two sets of three dashes) in order to be processed and converted to HTML.

While that behavior may be helpful for large, complex sites, sometimes it's easier to simply add a plain markdown file and have it render without fanfare.

This plugin does just that. Any Markdown file in your site's source will be treated as a Page and rendered as HTML, even if it doesn't have YAML front matter.



Related Topics



Leave a reply



Submit