diff --git a/bin/blog b/bin/blog index 9aba67f..7c78efe 100755 --- a/bin/blog +++ b/bin/blog @@ -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) diff --git a/lib/blog.rb b/lib/blog.rb index 73a960b..63d613c 100644 --- a/lib/blog.rb +++ b/lib/blog.rb @@ -5,3 +5,4 @@ require "constants" require "blog/blog" require "blog/article" +require "blog/index" diff --git a/lib/blog/blog.rb b/lib/blog/blog.rb index 9163a8e..5bed6f7 100644 --- a/lib/blog/blog.rb +++ b/lib/blog/blog.rb @@ -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 diff --git a/lib/blog/index.rb b/lib/blog/index.rb new file mode 100644 index 0000000..bd02c52 --- /dev/null +++ b/lib/blog/index.rb @@ -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 diff --git a/templates/2011/index.html.haml b/templates/2011/index.html.haml deleted file mode 100644 index 4b439c3..0000000 --- a/templates/2011/index.html.haml +++ /dev/null @@ -1,77 +0,0 @@ - -%html{:lang => "fr", :itemscope => "", :itemtype => "http://schema.org/Blog"} - %head - %meta{:charset => "utf-8"} - %title Vincent Tourraine - Blog 2011 - %link{:rel => "stylesheet", :type => "text/css", :href => "#{blog_url}styles/default.css?nav"} - / %link{:rel => "stylesheet", :type => "text/css", :href => "styles/default.css"} - %link{:rel => "stylesheet", :type => "text/css", :href => "http://fonts.googleapis.com/css?family=Nunito:300,700"} - - %link{:rel => "shortcut icon", :href => "http://www.vtourraine.net/img/vt-16.png"} - %link{:rel => "apple-touch-icon-precomposed", :href => "http://www.vtourraine.net/img/vt-114.png"} - %link{:rel => "apple-touch-icon-precomposed", :href => "http://www.vtourraine.net/img/vt-72.png", :sizes => "72x72"} - %link{:rel => "alternate", :type => "application/atom+xml", :href => "#{blog_url}feed.xml", :title => "Blog (Atom)"} - - %meta{:name => "viewport", :content => "width=device-width, user-scalable=no"} - - :javascript - var _gaq = _gaq || []; - _gaq.push(['_setAccount', 'UA-18279263-3']); - _gaq.push(['_trackPageview']); - - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); - - %body.blog - %header - #headline - %a{:href => "http://www.vtourraine.net/"} Vincent Tourraine - #main - %a{:href => "#{blog_url}"} Blog - - %section#blog - - %nav.links - %a{:href => "#{blog_url}2015/"} 2015 - %a{:href => "#{blog_url}2014/"} 2014 - %a{:href => "#{blog_url}2013/"} 2013 - %a{:href => "#{blog_url}2012/"} 2012 - %a{} 2011 - %a{:href => "#{blog_url}feed.xml"} Flux RSS - - %h1 Tous les billets 2011 - - - @articles.select { |a| a.date.year == 2011 }.reverse_each do |article| - %article - %h2 - %a{:href => "#{article.web_url}"} #{article.title} - %div - #{article.summary} - .meta - %time{:datetime =>"#{article.date.strftime('%F')}"} - #{article.locale_date}, - - article.keywords.each do |keyword| - %span.tag - \##{keyword} - - %footer - %nav - %a{:href => "http://www.vtourraine.net"} Vincent Tourraine - \/ - %a{:href => "http://www.vtourraine.net/projects/"} Projets - \/ - %span Blog - - #mail - Contact : - %a{:href => "mailto:me@vtourraine.net"} me@vtourraine.net - - .note - Ce blog est publié sous les termes de la licence Creative Commons CC BY-NC. - .note - Le contenu et le code de ce blog sont disponibles sur GitHub. - %br - N’hésitez pas à y proposer des corrections ou des suggestions d’améliorations. diff --git a/templates/2012/index.html.haml b/templates/2012/index.html.haml deleted file mode 100644 index 0b68123..0000000 --- a/templates/2012/index.html.haml +++ /dev/null @@ -1,77 +0,0 @@ - -%html{:lang => "fr", :itemscope => "", :itemtype => "http://schema.org/Blog"} - %head - %meta{:charset => "utf-8"} - %title Vincent Tourraine - Blog 2012 - %link{:rel => "stylesheet", :type => "text/css", :href => "#{blog_url}styles/default.css?nav"} - / %link{:rel => "stylesheet", :type => "text/css", :href => "styles/default.css"} - %link{:rel => "stylesheet", :type => "text/css", :href => "http://fonts.googleapis.com/css?family=Nunito:300,700"} - - %link{:rel => "shortcut icon", :href => "http://www.vtourraine.net/img/vt-16.png"} - %link{:rel => "apple-touch-icon-precomposed", :href => "http://www.vtourraine.net/img/vt-114.png"} - %link{:rel => "apple-touch-icon-precomposed", :href => "http://www.vtourraine.net/img/vt-72.png", :sizes => "72x72"} - %link{:rel => "alternate", :type => "application/atom+xml", :href => "#{blog_url}feed.xml", :title => "Blog (Atom)"} - - %meta{:name => "viewport", :content => "width=device-width, user-scalable=no"} - - :javascript - var _gaq = _gaq || []; - _gaq.push(['_setAccount', 'UA-18279263-3']); - _gaq.push(['_trackPageview']); - - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); - - %body.blog - %header - #headline - %a{:href => "http://www.vtourraine.net/"} Vincent Tourraine - #main - %a{:href => "#{blog_url}"} Blog - - %section#blog - - %nav.links - %a{:href => "#{blog_url}2015/"} 2015 - %a{:href => "#{blog_url}2014/"} 2014 - %a{:href => "#{blog_url}2013/"} 2013 - %a{} 2012 - %a{:href => "#{blog_url}2011/"} 2011 - %a{:href => "#{blog_url}feed.xml"} Flux RSS - - %h1 Tous les billets 2012 - - - @articles.select { |a| a.date.year == 2012 }.reverse_each do |article| - %article - %h2 - %a{:href => "#{article.web_url}"} #{article.title} - %div - #{article.summary} - .meta - %time{:datetime =>"#{article.date.strftime('%F')}"} - #{article.locale_date}, - - article.keywords.each do |keyword| - %span.tag - \##{keyword} - - %footer - %nav - %a{:href => "http://www.vtourraine.net"} Vincent Tourraine - \/ - %a{:href => "http://www.vtourraine.net/projects/"} Projets - \/ - %span Blog - - #mail - Contact : - %a{:href => "mailto:me@vtourraine.net"} me@vtourraine.net - - .note - Ce blog est publié sous les termes de la licence Creative Commons CC BY-NC. - .note - Le contenu et le code de ce blog sont disponibles sur GitHub. - %br - N’hésitez pas à y proposer des corrections ou des suggestions d’améliorations. diff --git a/templates/2013/index.html.haml b/templates/2013/index.html.haml deleted file mode 100644 index f98bb69..0000000 --- a/templates/2013/index.html.haml +++ /dev/null @@ -1,77 +0,0 @@ - -%html{:lang => "fr", :itemscope => "", :itemtype => "http://schema.org/Blog"} - %head - %meta{:charset => "utf-8"} - %title Vincent Tourraine - Blog 2013 - %link{:rel => "stylesheet", :type => "text/css", :href => "#{blog_url}styles/default.css?nav"} - / %link{:rel => "stylesheet", :type => "text/css", :href => "styles/default.css"} - %link{:rel => "stylesheet", :type => "text/css", :href => "http://fonts.googleapis.com/css?family=Nunito:300,700"} - - %link{:rel => "shortcut icon", :href => "http://www.vtourraine.net/img/vt-16.png"} - %link{:rel => "apple-touch-icon-precomposed", :href => "http://www.vtourraine.net/img/vt-114.png"} - %link{:rel => "apple-touch-icon-precomposed", :href => "http://www.vtourraine.net/img/vt-72.png", :sizes => "72x72"} - %link{:rel => "alternate", :type => "application/atom+xml", :href => "#{blog_url}feed.xml", :title => "Blog (Atom)"} - - %meta{:name => "viewport", :content => "width=device-width, user-scalable=no"} - - :javascript - var _gaq = _gaq || []; - _gaq.push(['_setAccount', 'UA-18279263-3']); - _gaq.push(['_trackPageview']); - - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); - - %body.blog - %header - #headline - %a{:href => "http://www.vtourraine.net/"} Vincent Tourraine - #main - %a{:href => "#{blog_url}"} Blog - - %section#blog - - %nav.links - %a{:href => "#{blog_url}2015/"} 2015 - %a{:href => "#{blog_url}2014/"} 2014 - %a{} 2013 - %a{:href => "#{blog_url}2012/"} 2012 - %a{:href => "#{blog_url}2011/"} 2011 - %a{:href => "#{blog_url}feed.xml"} Flux RSS - - %h1 Tous les billets 2013 - - - @articles.select { |a| a.date.year == 2013 }.reverse_each do |article| - %article - %h2 - %a{:href => "#{article.web_url}"} #{article.title} - %div - #{article.summary} - .meta - %time{:datetime =>"#{article.date.strftime('%F')}"} - #{article.locale_date}, - - article.keywords.each do |keyword| - %span.tag - \##{keyword} - - %footer - %nav - %a{:href => "http://www.vtourraine.net"} Vincent Tourraine - \/ - %a{:href => "http://www.vtourraine.net/projects/"} Projets - \/ - %span Blog - - #mail - Contact : - %a{:href => "mailto:me@vtourraine.net"} me@vtourraine.net - - .note - Ce blog est publié sous les termes de la licence Creative Commons CC BY-NC. - .note - Le contenu et le code de ce blog sont disponibles sur GitHub. - %br - N’hésitez pas à y proposer des corrections ou des suggestions d’améliorations. diff --git a/templates/2014/index.html.haml b/templates/2014/index.html.haml deleted file mode 100644 index 03e5495..0000000 --- a/templates/2014/index.html.haml +++ /dev/null @@ -1,77 +0,0 @@ - -%html{:lang => "fr", :itemscope => "", :itemtype => "http://schema.org/Blog"} - %head - %meta{:charset => "utf-8"} - %title Vincent Tourraine - Blog 2014 - %link{:rel => "stylesheet", :type => "text/css", :href => "#{blog_url}styles/default.css?nav"} - / %link{:rel => "stylesheet", :type => "text/css", :href => "styles/default.css"} - %link{:rel => "stylesheet", :type => "text/css", :href => "http://fonts.googleapis.com/css?family=Nunito:300,700"} - - %link{:rel => "shortcut icon", :href => "http://www.vtourraine.net/img/vt-16.png"} - %link{:rel => "apple-touch-icon-precomposed", :href => "http://www.vtourraine.net/img/vt-114.png"} - %link{:rel => "apple-touch-icon-precomposed", :href => "http://www.vtourraine.net/img/vt-72.png", :sizes => "72x72"} - %link{:rel => "alternate", :type => "application/atom+xml", :href => "#{blog_url}feed.xml", :title => "Blog (Atom)"} - - %meta{:name => "viewport", :content => "width=device-width, user-scalable=no"} - - :javascript - var _gaq = _gaq || []; - _gaq.push(['_setAccount', 'UA-18279263-3']); - _gaq.push(['_trackPageview']); - - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); - - %body.blog - %header - #headline - %a{:href => "http://www.vtourraine.net/"} Vincent Tourraine - #main - %a{:href => "#{blog_url}"} Blog - - %section#blog - - %nav.links - %a{:href => "#{blog_url}2015/"} 2015 - %a{} 2014 - %a{:href => "#{blog_url}2013/"} 2013 - %a{:href => "#{blog_url}2012/"} 2012 - %a{:href => "#{blog_url}2011/"} 2011 - %a{:href => "#{blog_url}feed.xml"} Flux RSS - - %h1 Tous les billets 2014 - - - @articles.select { |a| a.date.year == 2014 }.reverse_each do |article| - %article - %h2 - %a{:href => "#{article.web_url}"} #{article.title} - %div - #{article.summary} - .meta - %time{:datetime =>"#{article.date.strftime('%F')}"} - #{article.locale_date}, - - article.keywords.each do |keyword| - %span.tag - \##{keyword} - - %footer - %nav - %a{:href => "http://www.vtourraine.net"} Vincent Tourraine - \/ - %a{:href => "http://www.vtourraine.net/projects/"} Projets - \/ - %span Blog - - #mail - Contact : - %a{:href => "mailto:me@vtourraine.net"} me@vtourraine.net - - .note - Ce blog est publié sous les termes de la licence Creative Commons CC BY-NC. - .note - Le contenu et le code de ce blog sont disponibles sur GitHub. - %br - N’hésitez pas à y proposer des corrections ou des suggestions d’améliorations. diff --git a/templates/2015/index.html.haml b/templates/index-custom.html.haml similarity index 94% rename from templates/2015/index.html.haml rename to templates/index-custom.html.haml index 0a618ac..0de6f0e 100644 --- a/templates/2015/index.html.haml +++ b/templates/index-custom.html.haml @@ -2,7 +2,7 @@ %html{:lang => "fr", :itemscope => "", :itemtype => "http://schema.org/Blog"} %head %meta{:charset => "utf-8"} - %title Vincent Tourraine - Blog 2014 + %title Vincent Tourraine - Blog #{title} %link{:rel => "stylesheet", :type => "text/css", :href => "#{blog_url}styles/default.css?nav"} / %link{:rel => "stylesheet", :type => "text/css", :href => "styles/default.css"} %link{:rel => "stylesheet", :type => "text/css", :href => "http://fonts.googleapis.com/css?family=Nunito:300,700"} @@ -35,16 +35,16 @@ %section#blog %nav.links - %a{} 2015 + %a{:href => "#{blog_url}2015/"} 2015 %a{:href => "#{blog_url}2014/"} 2014 %a{:href => "#{blog_url}2013/"} 2013 %a{:href => "#{blog_url}2012/"} 2012 %a{:href => "#{blog_url}2011/"} 2011 %a{:href => "#{blog_url}feed.xml"} Flux RSS - %h1 Tous les billets 2015 + %h1 Tous les billets #{title} - - @articles.select { |a| a.date.year == 2015 }.reverse_each do |article| + - @articles.reverse_each do |article| %article{:class => article.thumbnail_url ? "thumbnailed listing" : "listing"} %h2 %a{:href => "#{article.web_url}"} #{article.title} diff --git a/wod.tu.md b/wod.tu.md index fd18a5e..3c73e12 100644 --- a/wod.tu.md +++ b/wod.tu.md @@ -3,16 +3,17 @@ ## Roadmap - Enable syntax coloring only on “code” tagged articles -- Add tag-based index -- Smarter year indexes (a.k.a. template for templates) - Draft folder for processed but unlisted articles -## v2.3.1 +## v2.4 +- [x] Add year based index +- [x] Add tag based index - [x] Colored output - [x] Fix article paragraphs x overflow on small screens + ## v2.3 - Post thumbnails