Skip to content

Instantly share code, notes, and snippets.

@jackcallister
Created July 29, 2019 10:14
Show Gist options
  • Save jackcallister/f993d34bc60ed8d2207538bb336e287e to your computer and use it in GitHub Desktop.
Save jackcallister/f993d34bc60ed8d2207538bb336e287e to your computer and use it in GitHub Desktop.
Rudimentary site compiler
require 'erb'
require 'tilt'
paths = Dir.glob('content/**/*').select{ |e| File.file? e }
paths.each do |path|
content = Tilt.new(path)
layout = Tilt.new('layouts/index.erb')
output = layout.render { content.render }
target = path.gsub(/content/, 'site').gsub(/.md/, '.html').gsub(/.html/, '/index.html')
File.write(path.gsub(/content/, 'site').gsub(/.md/, '.html'), output)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment