Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Making use of the tag metadata in order to generate a page for each t…

…ag linked to the related recipes.
  • Loading branch information...
commit 579001fa1c88343610863abd5af6d00371ec4828 1 parent 2ba7726
@gnrfan gnrfan authored tnm committed
View
43 Rakefile
@@ -21,11 +21,29 @@ end
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
# copy static stuff
`rm -rf public
- mkdir public
+ mkdir -p public/tag
cp -r site/* public
rm -rf public/_*`
@@ -43,10 +61,31 @@ task :default do
markdown = recipe.render('meta' => meta)
content = RDiscount.new(markdown).to_html
out.write layout.render('meta' => meta, 'content' => content)
- { 'title' => meta['title'], 'href' => name }
+ { 'title' => meta['title'], 'href' => name, 'tags' => meta['tags'] }
end
end
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
puts dest = 'public/index.html'
View
3  site/_views/recipe_header.liquid
@@ -4,3 +4,6 @@
Credit: {% for name in meta.credit %}{{ name }}{% unless forloop.last %}, {% endunless %}{% endfor %}
</div>
+<div class='tags'>
+ Tags: {% for tag in meta.tags %}<a href="/tag/{{ tag | slugify }}.html">{{ tag }}</a>{% unless forloop.last %}, {% endunless %}{% endfor %}
+</div>
View
8 site/_views/tag.liquid
@@ -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>
View
5 site/css/style.css
@@ -77,6 +77,11 @@ body pre {
font-style: italic;
}
+.tags {
+ font-style: italic;
+ margin-top: 10px;
+}
+
.index li {
list-style-image: url("/img/icon1.png");
list-style-type: square;
Please sign in to comment.
Something went wrong with that request. Please try again.