I'm trying to write a Jekyll plugin which generates an array of pages in a directory in a json file. So for a directory which contains foo.html and a sub-directory foo containing bar.html, it'd generate "foo, /foo/bar". I'm completely new to Ruby, does somone have any pointers?
1 Answer
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