Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismytton/cb500e0947d673fd7d5d to your computer and use it in GitHub Desktop.
Save chrismytton/cb500e0947d673fd7d5d to your computer and use it in GitHub Desktop.
Super simple static site system
#!/usr/bin/env ruby
require 'date'
require 'kramdown'
require 'erb'
abort "Usage: #$0 <posts_path>" if ARGV.empty?
Post = Struct.new(:path) do
def title
Date.strptime(File.basename(path, '.md'), '%Y-%m-%d').strftime('%d %B %Y')
end
def content
Kramdown::Document.new(File.read(path)).to_html
end
end
POSTS_PATH = File.join(ARGV[0], '*.md')
POSTS = Dir.glob(POSTS_PATH).sort.reverse.map { |path| Post.new(path) }
puts ERB.new(DATA.read).result
__END__
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>~crm</title>
<style>
body {
max-width: 600px;
margin: 0 auto;
padding: 10px;
}
</style>
</head>
<body>
<h1>~crm</h1>
<% POSTS.each do |post| %>
<h2><%= post.title %></h2>
<div><%= post.content %></div>
<% end %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment