Very well thought @MichaelCurrin.
But I better explain my use case that led me to consider using that piece of old code.
I need to create an index.html
for each folder, including root, that lists the files/folders in it. I have something in place here directory_index.rb · GitHub that works but not completely as expected as the generated index.html
files trigger the watch when a file is changed. I tried generating the files in the _site
folder directly but I can’t get the index-html
files to be kept after the build even using keep_files
configuration (does not work well with wildcards).
I started working on a Generator plugin to achieve the same thing but I’m not familiar with Ruby and the Jekyll Page class so I can’t get to put any content to the generated index.html
file using the following code as base:
module CreateIndexPlugin
class IndexPageGenerator < Jekyll::Generator
safe true
def generate(site)
site.pages.each do |page|
site.static_files << IndexPage.new(site, page)
end
end
end
# Subclass of `Jekyll::Page` with custom method definitions.
class IndexPage < Jekyll::Page
def initialize(site, page)
@site = site # the current site instance.
@base = site.source # path to the source directory.
@dir = page.dir # the directory the page will reside in.
# All pages have the same filename, so define attributes straight away.
@basename = 'index' # filename without the extension.
@ext = '.html' # the extension.
@name = 'index.html' # basically @basename + @ext.
end
end
end
Thanks for the help BTW, I really appreciate it.