Last active
August 29, 2015 14:07
-
-
Save chrismytton/cb500e0947d673fd7d5d to your computer and use it in GitHub Desktop.
Super simple static site system
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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