Skip to content

Instantly share code, notes, and snippets.

@kez
Created April 13, 2010 08:14
Show Gist options
  • Select an option

  • Save kez/364416 to your computer and use it in GitHub Desktop.

Select an option

Save kez/364416 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous revised this gist May 6, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions jekyll tag pages
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    @@site_url = 'http://www.mysite.com'

    task :cloud_basic do
    puts 'Generating tag cloud...'
  2. @invalid-email-address Anonymous created this gist Apr 13, 2010.
    112 changes: 112 additions & 0 deletions jekyll tag pages
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,112 @@

    task :cloud_basic do
    puts 'Generating tag cloud...'
    require 'rubygems'
    require 'jekyll'
    include Jekyll::Filters

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

    html = ''

    site.categories.sort.each do |category, posts|

    s = posts.count
    font_size = 12 + (s*1.2);
    html << "<a href=\"#{@@site_url}/tag/#{category}/\" title=\"Pages tagged #{category}\" style=\"font-size: #{font_size}px; line-height:#{font_size}px\" rel=\"tag\">#{category}</a> "
    end

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

    puts 'Done.'
    end


    task :cloud do
    puts 'Generating tag cloud...'
    require 'rubygems'
    require 'jekyll'
    include Jekyll::Filters

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


    html =<<-HTML
    ---
    layout: default
    title: Tags
    type: A tag cloud
    ---

    <h1>Tag cloud for {{site.title}}</h1>

    <p>Click on a tag to see the relevant posts.</p>
    HTML

    site.categories.sort.each do |category, posts|
    next if category == ".net"
    html << <<-HTML
    HTML

    s = posts.count
    font_size = 12 + (s*1.5);
    html << "<a href=\"#{@@site_url}/tag/#{category}/\" title=\"Entries tagged #{category}\" style=\"font-size: #{font_size}px; line-height:#{font_size}px\">#{category}</a> "
    end

    html << "<p>You may also wish to browse the <a href=\"#{@@site_url}/archives/\" title=\"Archives for {{site.title}}\">archives</a>."


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

    puts 'Done.'
    end

    desc 'Generate tags page'
    task :tags do
    puts "Generating tags..."
    require 'rubygems'
    require 'jekyll'
    include Jekyll::Filters

    options = Jekyll.configuration({})
    site = Jekyll::Site.new(options)
    site.read_posts('')
    site.categories.sort.each do |category, posts|

    next if category == ".net"
    html = ''
    html << <<-HTML
    ---
    layout: default
    title: Entries tagged "#{category}"
    type: "#{category.gsub(/\b\w/){$&.upcase}}"
    ---
    <h1 id="#{category}">Entries tagged "#{category}"</h1>
    <a href="#{@@site_url}/tags/" title="Tag cloud for {{site.title}}">&laquo; Show all tags...</a>
    HTML

    html << '<ul class="posting_list">'
    posts.each do |post|
    post_data = post.to_liquid
    html << <<-HTML
    <li><a href="#{@@site_url}/#{post.url}" rel="tag" title="Entries tagged #{post_data['title']}">#{post_data['title']}</a></li>
    HTML
    end
    html << '</ul>'

    html << '<p>You may also be interested in browsing the <a href="#'+@@site_url+'/archives/" title="Archives for {{site.title}}">archives</a> or seeing <a href="'+@@site_url+'/tags/" title="Tag cloud for {{site.title}}">the tag cloud for {{site.title}}</a>.'
    FileUtils.mkdir_p "tag/#{category}"
    File.open("tag/#{category}/index.html", 'w+') do |file|
    file.puts html
    end
    end
    puts 'Done.'
    end