Lalit (owner)

Fork Of

Revisions

gist: 144254 Download_button fork
public
Public Clone URL: git://gist.github.com/144254.git
Embed All Files: show embed
generate_tags.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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