Skip to content

Instantly share code, notes, and snippets.

@alexyoung
Created July 9, 2009 11:02

Revisions

  1. alexyoung created this gist Jul 9, 2009.
    46 changes: 46 additions & 0 deletions generate_tags.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    namespace :tags do
    task :generate do
    puts 'Generating tags...'
    require 'rubygems'
    require 'jekyll'
    include Jekyll::Filters

    options = Jekyll.configuration({})
    site = Jekyll::Site.new(options)
    site.read_posts('')

    html =<<-HTML
    ---
    layout: default
    title: Tags
    ---
    <h2>Tags</h2>
    HTML

    site.categories.sort.each do |category, posts|
    html << <<-HTML
    <h3 id="#{category}">#{category}</h3>
    HTML

    html << '<ul class="posts">'
    posts.each do |post|
    post_data = post.to_liquid
    html << <<-HTML
    <li>
    <div>#{date_to_string post.date}</div>
    <a href="#{post.url}">#{post_data['title']}</a>
    </li>
    HTML
    end
    html << '</ul>'
    end

    File.open('tags.html', 'w+') do |file|
    file.puts html
    end

    puts 'Done.'
    end
    end