Skip to content

Commit

Permalink
Add tag based and year based index
Browse files Browse the repository at this point in the history
  • Loading branch information
vtourraine committed Apr 18, 2015
1 parent 805af0f commit 0b14f60
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 320 deletions.
13 changes: 8 additions & 5 deletions bin/blog
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ blog.articles.each { |article|
}

blog.generate_index "templates/index.html.haml", haml_options
blog.generate_index "templates/2011/index.html.haml", haml_options
blog.generate_index "templates/2012/index.html.haml", haml_options
blog.generate_index "templates/2013/index.html.haml", haml_options
blog.generate_index "templates/2014/index.html.haml", haml_options
blog.generate_index "templates/2015/index.html.haml", haml_options
blog.generate_index "templates/feed.xml.haml", haml_options
blog.generate_index "templates/articles.json.haml", haml_options

blog.generate_index_year 2011, haml_options
blog.generate_index_year 2012, haml_options
blog.generate_index_year 2013, haml_options
blog.generate_index_year 2014, haml_options
blog.generate_index_year 2015, haml_options
blog.generate_index_tag "livre", haml_options
blog.generate_index_tag "iOS", haml_options

blog.generate_style "default.css.scss"

puts "Ready! (#{blog.articles.count} articles)".colorize(:green)
1 change: 1 addition & 0 deletions lib/blog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
require "constants"
require "blog/blog"
require "blog/article"
require "blog/index"
18 changes: 18 additions & 0 deletions lib/blog/blog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ def generate_index(template_url, haml_options)
end
end

def generate_index_year(year, haml_options)
puts 'Generating index year: “' + year.to_s + '”'

index = Index.new
index.title = year.to_s
index.articles = @articles.select { |a| a.date.year == year }
index.generate_index("templates/index-custom.html.haml", RENDERED_DIRECTORY+year.to_s+"/index.html", haml_options)
end

def generate_index_tag(tag, haml_options)
puts 'Generating index tag: “' + tag + '”'

index = Index.new
index.title = tag
index.articles = @articles.select { |a| a.keywords.include? tag }
index.generate_index("templates/index-custom.html.haml", RENDERED_DIRECTORY+"tags/"+tag.downcase+".html", haml_options)
end

def generate_style(scss_name)
puts 'Generating style: “' + scss_name + '”'
style_input_url = STYLES_DIRECTORY + scss_name
Expand Down
19 changes: 19 additions & 0 deletions lib/blog/index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Index
attr_accessor :articles
attr_accessor :title
attr_reader :blog_url

def initialize
@articles = Array.new
@blog_url = BLOG_ROOT_URL
end

def generate_index(template_url, output_url, haml_options)
index_template = Haml::Engine.new(File.read(template_url), haml_options)
index_output = index_template.render self
FileUtils.mkdir_p(File.dirname(output_url))
File.open(output_url, "w") do |file|
file.write index_output
end
end
end
77 changes: 0 additions & 77 deletions templates/2011/index.html.haml

This file was deleted.

77 changes: 0 additions & 77 deletions templates/2012/index.html.haml

This file was deleted.

77 changes: 0 additions & 77 deletions templates/2013/index.html.haml

This file was deleted.

77 changes: 0 additions & 77 deletions templates/2014/index.html.haml

This file was deleted.

Loading

0 comments on commit 0b14f60

Please sign in to comment.