Skip to content

Instantly share code, notes, and snippets.

@changemewtf
Created August 21, 2014 18:01
Show Gist options
  • Save changemewtf/e70e784ec57ef72b1c33 to your computer and use it in GitHub Desktop.
Save changemewtf/e70e784ec57ef72b1c33 to your computer and use it in GitHub Desktop.
class CodefileGenerator < Jekyll::Generator
NON_CODE_EXTENSIONS = [
'html',
'md'
]
is_dotfile = proc { |f| ['.', '..'].include? f }
f_ext = proc { |f| f.slice /\.(.*)$/, 1 }
is_non_codefile = proc { |f| non_code_extensions.include? f_ext[f] }
def generate(site)
site.pages.each do |page|
dir = File.dirname(page.path)
if !File.exists? dir
# for generated pages (like week schedules)
next
end
codefiles = Dir.entries(dir)
.reject(&is_dotfile)
.reject(&is_non_codefile)
page.data['codefiles'] = codefiles
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment