all repos — h3rald @ 19e4a5e256c7bbd728825af8bd1f16b7abbb9137

The sources of https://h3rald.com

Created task for tag pages generation.
h3rald h3rald@h3rald.com
Mon, 10 Aug 2009 11:17:43 +0200
commit

19e4a5e256c7bbd728825af8bd1f16b7abbb9137

parent

edd63e57923ff84b9ab2ad7db99841e5e019b896

3 files changed, 56 insertions(+), 11 deletions(-)

jump to
M layouts/default.htmlayouts/default.htm

@@ -90,9 +90,7 @@ </ul>

<!-- CONTENT START --> <div id="content" class="clearfix"> <div id="search_results"></div> - <% if @page.type != 'page' then %> <h2><%= @page.title %></h2> - <% end %> <% if @page.permalink == 'home' then %> <div id="slider"> <div class="scroll">
M resources/js/init.jsresources/js/init.js

@@ -14,10 +14,12 @@ node = node.firstChild;

} var text = node.nodeValue; var first_letter = text.substr(0,1); - node.nodeValue = text.slice(1,text.length); - $('<span></span>').addClass('dropcap').html(first_letter).prependTo( first_paragraph ); - }); - Cufon.replace('.dropcap', {fontFamily: 'Mutlu'}); - + if (first_letter.match(/[a-zA-Z]/)) + { + node.nodeValue = text.slice(1,text.length); + $('<span></span>').addClass('dropcap').html(first_letter).prependTo( first_paragraph ); + }); + Cufon.replace('.dropcap', {fontFamily: 'Mutlu'}); + } });
M tasks/site.raketasks/site.rake

@@ -4,6 +4,34 @@ require 'pathname'

require 'fileutils' require 'nanoc' +module SiteUtils + + def write_tag_page(dir, name, count) + # Create tag page + meta = {} + meta[:title] = "Tag: #{name}" + meta[:type] = 'page' + meta[:filters_pre] = ['erb', 'redcloth'] + meta[:permalink] = name + contents = %{\n#{count} items are tagged with _#{name}_: + +<% @site.pages.select{|p| p.attributes[:tags] && p.attributes[:tags].include?('#{name}')}.sort{|a,b| a.attributes[:date] <=> b.attributes[:date]}.reverse.each do |pg| +dir = (pg.attributes[:type] == 'page') ? '' : '/articles' +%>* <span class="<%= pg.attributes[:type] %>_link"> <a href="<%= dir %>/<%= pg.attributes[:permalink] %>/"><%= pg.attributes[:title] %></a></span> +<% end %> + } + # Write file + (dir/"#{name}.textile").open('w+') do |f| + f.print "--" + f.puts meta.to_yaml + f.puts "-----" + f.puts contents + end + + end +end + +include SiteUtils namespace :site do

@@ -25,10 +53,27 @@ task :rebuild => [:clear_output, :update] do

end task :build_tag_pages do - # TODO - #site = Nanoc::Site.new(YAML.load_file('config.yaml')) - #site.load_data - # site.pages.each { |p| p.tags ...} + site = Nanoc::Site.new(YAML.load_file('config.yaml')) + site.load_data + tagdir = Pathname(Dir.pwd)/'content/tags' + tagdir.rmtree if tagdir.exist? + tagdir.mkpath + tags = {} + # Collect tag and page data + site.pages.each do |p| + next unless p.attributes[:tags] + p.attributes[:tags].each do |t| + if tags[t] + tags[t] = tags[t]+1 + else + tags[t] = 1 + end + end + end + # Write pages + tags.each_pair do |k, v| + write_tag_page tagdir, k, v + end end task :copy_resources do