1
0
Fork 0
forked from wezm/wezm.net

Start articles page with JSON representation

This commit is contained in:
Wesley Moore 2009-11-23 13:34:17 +11:00
parent cebe17fde4
commit 19be2ada2e
6 changed files with 77 additions and 0 deletions

14
Rules
View file

@ -4,11 +4,25 @@ compile '/' do
layout 'listing' layout 'listing'
end end
compile '/articles/', :rep => :json do
filter :erb
end
compile '/articles/' do
layout 'articles'
end
compile '*' do compile '*' do
filter :rdiscount filter :rdiscount
layout 'default' layout 'default'
end end
route '/articles/', :rep => :json do
item.identifier + 'index.json'
end
route '/articles/' do
item.identifier + 'index.html'
end
route '*' do route '*' do
item.identifier + 'index.html' item.identifier + 'index.html'
end end

7
content/articles.json Normal file
View file

@ -0,0 +1,7 @@
<%
articles = []
sorted_articles.each do |article|
articles << { :title => article[:title] }
end
%>
<%= articles.to_json %>

2
content/articles.yaml Normal file
View file

@ -0,0 +1,2 @@
---
title: Articles

49
layouts/articles.html Normal file
View file

@ -0,0 +1,49 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title><%= @item[:title] %></title>
<link rel="stylesheet" href="/css/reset.css" type="text/css" media="screen,projector" />
<link rel="stylesheet" href="/css/style.css" type="text/css" media="screen,projector" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script src="/js/script.js" type="text/javascript"></script>
<script type="text/javascript">
var articles;
jQuery(function() {
// load JSON
// get( url, [data], [callback], [type] )
jQuery.get('/articles/index.json', {}, function(data) {
articles = data;
console.log(data);
}, 'json');
});
</script>
</head>
<body>
<%= render 'header' %>
<div id="main">
<h1><%= @item[:title] %></h1>
<ul class="articles">
<% sorted_articles[0..9].each do |article| %>
<% post_date = WezM::Helpers.post_date(article) %>
<li>
<abbr class="calender date" title="<%= post_date.iso8601 %>">
<span class="day"><%= post_date.day %></span>
<span class="month"><%= post_date.strftime('%b') %></span>
<span class="year"><%= post_date.year %></span>
</abbr>
<a href="<%= article.reps.first.path %>"><%= article[:title] %></a>
</li>
<% end %>
</ul>
<div class="pagination">
<a href="">&laquo; Newer</a>
|
<a href="">Older &raquo;</a>
</div>
</div>
<%= render 'footer' %>
</body>
</html>

2
layouts/articles.yaml Normal file
View file

@ -0,0 +1,2 @@
--- {}

View file

@ -1,4 +1,7 @@
# All files in the 'lib' directory will be loaded # All files in the 'lib' directory will be loaded
# before nanoc starts compiling. # before nanoc starts compiling.
require 'json'
include Nanoc3::Helpers::Rendering include Nanoc3::Helpers::Rendering
include Nanoc3::Helpers::Blogging include Nanoc3::Helpers::Blogging