Skip to content

Commit

Permalink
Making use of the tag metadata in order to generate a page for each t…
Browse files Browse the repository at this point in the history
…ag linked to the related recipes.
  • Loading branch information
gnrfan authored and tnm committed Jul 6, 2010
1 parent 2ba7726 commit 579001f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
43 changes: 41 additions & 2 deletions Rakefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,11 +21,29 @@ end


Liquid::Template.register_tag('code_snippet', CodeSnippet) Liquid::Template.register_tag('code_snippet', CodeSnippet)


# slugify method for strings
class String
def slugify
slug = self.downcase.gsub(/'/, '').gsub(/[^a-z0-9]+/, '_')
slug = slug.chop! if slug =~ /_$/
return slug
end
end


# custom liquid filter
module SlugifyFilter
def slugify(input)
input.slugify
end
end

Liquid::Template.register_filter(SlugifyFilter)

# default task
task :default do task :default do
# copy static stuff # copy static stuff
`rm -rf public `rm -rf public
mkdir public mkdir -p public/tag
cp -r site/* public cp -r site/* public
rm -rf public/_*` rm -rf public/_*`


Expand All @@ -43,10 +61,31 @@ task :default do
markdown = recipe.render('meta' => meta) markdown = recipe.render('meta' => meta)
content = RDiscount.new(markdown).to_html content = RDiscount.new(markdown).to_html
out.write layout.render('meta' => meta, 'content' => content) out.write layout.render('meta' => meta, 'content' => content)
{ 'title' => meta['title'], 'href' => name } { 'title' => meta['title'], 'href' => name, 'tags' => meta['tags'] }
end end
end end
end.compact end.compact

# generate tag pages
tags_dict = Hash.new
recipes.each do |recipe|
recipe['tags'].each do |tag|
if not tags_dict.keys.include? tag
tags_dict[tag] = Array.new
end
tags_dict[tag] << recipe
end
end

tags_dict.keys.each do |tag|
puts dest = "public/tag/#{tag.slugify}.html"
recipes_for_tag = tags_dict[tag]
open(dest, 'w') do |out|
tag_page = Liquid::Template.parse(open('site/_views/tag.liquid').read())
out.write layout.render('content' => tag_page.render(
'tag' => tag, 'recipes' => recipes_for_tag))
end
end


# generate index page # generate index page
puts dest = 'public/index.html' puts dest = 'public/index.html'
Expand Down
3 changes: 3 additions & 0 deletions site/_views/recipe_header.liquid
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
Credit: {% for name in meta.credit %}{{ name }}{% unless forloop.last %}, {% endunless %}{% endfor %} Credit: {% for name in meta.credit %}{{ name }}{% unless forloop.last %}, {% endunless %}{% endfor %}
</div> </div>


<div class='tags'>
Tags: {% for tag in meta.tags %}<a href="/tag/{{ tag | slugify }}.html">{{ tag }}</a>{% unless forloop.last %}, {% endunless %}{% endfor %}
</div>
8 changes: 8 additions & 0 deletions site/_views/tag.liquid
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Recipes for tag "{{ tag }}"</h1>
<p>Recipes tagged <strong>{{ tag }}</strong>:</p>

<ul class='index'>
{% for recipe in recipes %}
<li><a href="{{ recipe.href }}">{{ recipe.title }}</a></li>
{% endfor %}
</ul>
5 changes: 5 additions & 0 deletions site/css/style.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ body pre {
font-style: italic; font-style: italic;
} }


.tags {
font-style: italic;
margin-top: 10px;
}

.index li { .index li {
list-style-image: url("/img/icon1.png"); list-style-image: url("/img/icon1.png");
list-style-type: square; list-style-type: square;
Expand Down

0 comments on commit 579001f

Please sign in to comment.