Skip to content

Instantly share code, notes, and snippets.

@chrismytton
Last active August 29, 2015 14:07
Show Gist options
  • Save chrismytton/cb500e0947d673fd7d5d to your computer and use it in GitHub Desktop.
Save chrismytton/cb500e0947d673fd7d5d to your computer and use it in GitHub Desktop.

Revisions

  1. chrismytton revised this gist Oct 13, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions generateblog.rb
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,8 @@ def content
    end
    end

    POSTS_PATH = ARGV[0]
    POSTS = Dir.glob(POSTS_PATH + '/*.md').map { |path| Post.new(path) }
    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

  2. chrismytton renamed this gist Oct 13, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. chrismytton renamed this gist Oct 13, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. chrismytton revised this gist Oct 13, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion static.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    require 'kramdown'
    require 'erb'

    POSTS_PATH = File.expand_path('../../posts', __FILE__)
    abort "Usage: #$0 <posts_path>" if ARGV.empty?

    Post = Struct.new(:path) do
    def title
    @@ -15,6 +15,7 @@ def content
    end
    end

    POSTS_PATH = ARGV[0]
    POSTS = Dir.glob(POSTS_PATH + '/*.md').map { |path| Post.new(path) }

    puts ERB.new(DATA.read).result
  5. chrismytton created this gist Oct 13, 2014.
    46 changes: 46 additions & 0 deletions static.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/usr/bin/env ruby
    require 'date'
    require 'kramdown'
    require 'erb'

    POSTS_PATH = File.expand_path('../../posts', __FILE__)

    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 = Dir.glob(POSTS_PATH + '/*.md').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>