From 5da45019a8209de040e0715a74a6b4ebc87901b8 Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Sat, 30 Jan 2010 16:50:07 +1100 Subject: [PATCH] Bunch of new files to support archive listings --- Rules | 25 ++++++++++++++----- content/articles.yaml | 1 + content/{articles.json => articles/json.json} | 2 +- content/articles/json.yaml | 2 ++ content/personal/articles.html | 4 ++- content/personal/articles/json.json | 7 ++++++ content/personal/articles/json.yaml | 2 ++ content/technical/articles.html | 4 ++- content/technical/articles/json.json | 7 ++++++ content/technical/articles/json.yaml | 2 ++ layouts/articles.html | 15 +++-------- layouts/default.html | 2 +- lib/articles.rb | 22 ++++++++++++++++ lib/default.rb | 3 ++- 14 files changed, 76 insertions(+), 22 deletions(-) rename content/{articles.json => articles/json.json} (65%) create mode 100644 content/articles/json.yaml create mode 100644 content/personal/articles/json.json create mode 100644 content/personal/articles/json.yaml create mode 100644 content/technical/articles/json.json create mode 100644 content/technical/articles/json.yaml create mode 100644 lib/articles.rb diff --git a/Rules b/Rules index 5c770db..8057967 100644 --- a/Rules +++ b/Rules @@ -4,13 +4,23 @@ compile '/' do layout 'home' end -compile '/articles/', :rep => :json do +compile '/articles/json/' do filter :erb end +compile '/technical/articles/json/' do + filter :erb +end +compile '/personal/articles/json/' do + filter :erb +end + compile '/articles/' do layout 'articles' end -compile '/*/articles/' do +compile '/technical/articles/' do + layout 'articles' +end +compile '/personal/articles/' do layout 'articles' end @@ -19,11 +29,14 @@ compile '*' do layout 'default' end -route '/articles/', :rep => :json do - item.identifier + 'index.json' +route '/articles/json/' do + item.identifier + 'articles.json' end -route '/articles/' do - item.identifier + 'index.html' +route '/technical/articles/json/' do + item.identifier + 'articles.json' +end +route '/personal/articles/json/' do + item.identifier + 'articles.json' end route '*' do diff --git a/content/articles.yaml b/content/articles.yaml index 36c1c5f..349c365 100644 --- a/content/articles.yaml +++ b/content/articles.yaml @@ -1,2 +1,3 @@ --- title: Articles +body_class: articles \ No newline at end of file diff --git a/content/articles.json b/content/articles/json.json similarity index 65% rename from content/articles.json rename to content/articles/json.json index ce6e07f..5f5af20 100644 --- a/content/articles.json +++ b/content/articles/json.json @@ -1,7 +1,7 @@ <% articles = [] sorted_articles.each do |article| - articles << { :title => article[:title] } + articles << article_to_json(article) end %> <%= articles.to_json %> \ No newline at end of file diff --git a/content/articles/json.yaml b/content/articles/json.yaml new file mode 100644 index 0000000..e521976 --- /dev/null +++ b/content/articles/json.yaml @@ -0,0 +1,2 @@ +--- +title: A New Item diff --git a/content/personal/articles.html b/content/personal/articles.html index b2cbfed..f214efe 100644 --- a/content/personal/articles.html +++ b/content/personal/articles.html @@ -1 +1,3 @@ -Hi, I'm a new item! +<% sorted_articles[0..9].each do |article| %> + <%= render 'article', :article => article %> +<% end %> diff --git a/content/personal/articles/json.json b/content/personal/articles/json.json new file mode 100644 index 0000000..d4267f3 --- /dev/null +++ b/content/personal/articles/json.json @@ -0,0 +1,7 @@ +<% + articles = [] + personal_articles.each do |article| + articles << article_to_json(article) + end +%> +<%= articles.to_json %> \ No newline at end of file diff --git a/content/personal/articles/json.yaml b/content/personal/articles/json.yaml new file mode 100644 index 0000000..e521976 --- /dev/null +++ b/content/personal/articles/json.yaml @@ -0,0 +1,2 @@ +--- +title: A New Item diff --git a/content/technical/articles.html b/content/technical/articles.html index b2cbfed..f214efe 100644 --- a/content/technical/articles.html +++ b/content/technical/articles.html @@ -1 +1,3 @@ -Hi, I'm a new item! +<% sorted_articles[0..9].each do |article| %> + <%= render 'article', :article => article %> +<% end %> diff --git a/content/technical/articles/json.json b/content/technical/articles/json.json new file mode 100644 index 0000000..9ba992b --- /dev/null +++ b/content/technical/articles/json.json @@ -0,0 +1,7 @@ +<% + articles = [] + technical_articles.each do |article| + articles << article_to_json(article) + end +%> +<%= articles.to_json %> \ No newline at end of file diff --git a/content/technical/articles/json.yaml b/content/technical/articles/json.yaml new file mode 100644 index 0000000..e521976 --- /dev/null +++ b/content/technical/articles/json.yaml @@ -0,0 +1,2 @@ +--- +title: A New Item diff --git a/layouts/articles.html b/layouts/articles.html index aacf95b..6b5991c 100644 --- a/layouts/articles.html +++ b/layouts/articles.html @@ -1,12 +1,7 @@ - - - <%= @item[:title] %> - - - + <%= render 'head_common' %> @@ -15,15 +10,13 @@

<%= @item[:title] %>

<%= render 'footer' %> diff --git a/layouts/default.html b/layouts/default.html index 6c4f293..d5589f2 100644 --- a/layouts/default.html +++ b/layouts/default.html @@ -8,7 +8,7 @@ - +> <%= render 'header' %>

<%= @item[:title] %>

diff --git a/lib/articles.rb b/lib/articles.rb new file mode 100644 index 0000000..cf029da --- /dev/null +++ b/lib/articles.rb @@ -0,0 +1,22 @@ +module WezM + module Helpers + module Articles + + def personal_articles + sorted_articles.select { |a| a.identifier =~ %r{^/personal/} } + end + + def technical_articles + sorted_articles.select { |a| a.identifier =~ %r{^/technical/} } + end + + def article_to_json(article) + { + :title => article[:title], + :path => article.identifier, + } + end + + end + end +end \ No newline at end of file diff --git a/lib/default.rb b/lib/default.rb index 0d5ae7d..f252f08 100644 --- a/lib/default.rb +++ b/lib/default.rb @@ -4,4 +4,5 @@ require 'json' include Nanoc3::Helpers::Rendering -include Nanoc3::Helpers::Blogging \ No newline at end of file +include Nanoc3::Helpers::Blogging +include WezM::Helpers::Articles \ No newline at end of file