add yearly and monthly archive indexes

This commit is contained in:
Sami Samhuri 2014-03-10 00:21:21 -07:00
parent 4d23c27584
commit 24f60083a2
46 changed files with 199 additions and 32 deletions

View file

@ -68,6 +68,7 @@ class Blag
def posts
@posts ||= begin
Dir[File.join(@dir, 'posts/20*/*')].map do |dir|
next unless dir =~ /\/\d\d$/
json = File.read File.join(dir, '_data.json')
data = JSON.parse json
prefix = dir.sub(@dir, '')
@ -85,7 +86,7 @@ class Blag
post['rfc822'] = Time.at(post['timestamp']).rfc822
post
end
end.flatten.sort_by { |p| -p['timestamp'] }.first(@num_posts)
end.flatten.compact.sort_by { |p| -p['timestamp'] }.first(@num_posts)
end
end

View file

@ -94,10 +94,10 @@
<a class="permalink" href="<%= url %>">&infin;</a>
</header>
<%- yield %>
<div class="row clearfix">
<p class="fin clearfix"><i class="fa fa-code"></i></p>
</div>
</article>
<div class="row clearfix">
<p class="fin clearfix"><i class="fa fa-code"></i></p>
</div>
<% } else if (typeof date != 'undefined') { -%>
<article class="container">
<header>
@ -105,25 +105,20 @@
<time><%= date %></time>
</header>
<%- yield %>
<div class="row clearfix">
<p class="fin"><i class="fa fa-code"></i></p>
</div>
</article>
<div class="row clearfix">
<p class="fin"><i class="fa fa-code"></i></p>
</div>
<% } else if (typeof title != 'undefined') { -%>
<article class="container">
<h2><%= title %></h2>
<%- yield %>
<div class="row clearfix">
<p class="fin"><i class="fa fa-code"></i></p>
</div>
</article>
<div class="row clearfix">
<p class="fin"><i class="fa fa-code"></i></p>
</div>
<% } else { -%>
<article class="container">
<%- yield %>
<div class="row clearfix">
<p class="fin"><i class="fa fa-code"></i></p>
</div>
</article>
<%- yield %>
<% } -%>
<footer class="container">

View file

@ -22,7 +22,9 @@
<% function posts(dir, year) { -%>
<% if (!dir) return -%>
<h3><%= year %></h3>
<h3>
<a href="/posts/<%= year %>"><%= year %></a>
</h3>
<% for (var month = 12; month >= 1; month--) { -%>
<% var monthDir = dir[pad(month)] -%>
@ -38,7 +40,7 @@
<% } else { -%>
<a href="<%= post.url %>"><%= post.title %></a>
<% } -%>
<span class="date"><%= formatDate(1000 * post.timestamp) %></span>
<time><%= formatDate(1000 * post.timestamp) %></time>
</li>
<% } -%>
</ul>

View file

@ -257,12 +257,11 @@ ul.archive {
text-decoration: none;
}
.date {
time {
font-size: 80%;
padding-left: 0.5rem;
color: lighten(@text, 30%);
// float: right;
} /* .date */
}
} /* li */
@ -345,12 +344,12 @@ article {
}
p.fin {
text-align: center;
color: darken(@background, 20%);
margin: 1rem 0;
}
}
p.fin {
text-align: center;
color: darken(@background, 20%);
margin: 1rem 0;
}
blockquote {

View file

@ -1,3 +1,4 @@
<div class="container">
<% var posts = public._data.posts -%>
<% for (var i in posts) { -%>
@ -26,10 +27,9 @@
<% } -%>
<% if (i < posts.length - 1) { -%>
<div class="row clearfix">
<p class="fin"><i class="fa fa-code"></i></p>
</div>
<% } -%>
<div class="row clearfix">
<p class="fin"><i class="fa fa-code"></i></p>
</div>
<% } -%>
</div>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../_year') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../_year') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../_year') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../_year') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../_year') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../_year') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../_year') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../_year') %>

View file

@ -0,0 +1 @@
<%- partial('../../_month') %>

View file

@ -0,0 +1 @@
<%- partial('../_year') %>

52
public/posts/_month.ejs Normal file
View file

@ -0,0 +1,52 @@
<% function pad(n) { -%>
<% return +n < 10 ? '0' + n : String(n) -%>
<% } -%>
<% var _months = 'January February March April May June July August September October November December'.split(' ') -%>
<% var _shortMonths = _months.map(function(m) { return m.slice(0, 3) }) -%>
<% function formatDate(t) { -%>
<% var d = new Date(t) -%>
<% return _shortMonths[d.getMonth()] + ' ' + d.getDate() -%>
<% } -%>
<% function sortPosts(dir) { -%>
<% var slugs = Object.keys(dir._data) -%>
<% var posts = slugs.map(function(slug) { -%>
<% var d = dir._data[slug]; -%>
<% d.slug = slug; -%>
<% return d; -%>
<% }) -%>
<% posts.sort(function(a, b) { -%>
<% var t1 = a.timestamp -%>
<% var t2 = b.timestamp -%>
<% return t1 < t2 ? -1 : (t1 > t2 ? 1 : 0) -%>
<% }) -%>
<% return posts -%>
<% } -%>
<% var posts = sortPosts(public.posts[current.path[1]][current.path[2]]) -%>
<% for (var i in posts) { -%>
<% var post = posts[i] -%>
<% if (post.hidden) continue -%>
<article class="container">
<header>
<% if (post.link) { -%>
<h2><a href="<%= post.link %>">&rarr; <%= post.title %></a></h2>
<time><%= post.date %></time>
<a class="permalink" href="<%= post.url %>">&infin;</a>
<% } else { -%>
<h2><a href="<%= post.url %>"><%= post.title %></a></h2>
<time><%= post.date %></time>
<% } -%>
</header>
<%- partial(current.path[1] + '/' + current.path[2] + '/' + post.slug) %>
</article>
<div class="row clearfix">
<p class="fin"><i class="fa fa-code"></i></p>
</div>
<% } -%>

64
public/posts/_year.ejs Normal file
View file

@ -0,0 +1,64 @@
<% function pad(n) { -%>
<% return +n < 10 ? '0' + n : String(n) -%>
<% } -%>
<% var _months = 'January February March April May June July August September October November December'.split(' ') -%>
<% var _shortMonths = _months.map(function(m) { return m.slice(0, 3) }) -%>
<% function formatDate(t) { -%>
<% var d = new Date(t) -%>
<% return _shortMonths[d.getMonth()] + ' ' + d.getDate() -%>
<% } -%>
<% function sortPosts(dir) { -%>
<% var slugs = Object.keys(dir._data) -%>
<% var posts = slugs.map(function(slug) { -%>
<% var d = dir._data[slug]; -%>
<% d.slug = slug; -%>
<% return d; -%>
<% }) -%>
<% posts.sort(function(a, b) { -%>
<% var t1 = a.timestamp -%>
<% var t2 = b.timestamp -%>
<% return t1 < t2 ? 1 : (t1 > t2 ? -1 : 0) -%>
<% }) -%>
<% return posts -%>
<% } -%>
<% function posts(dir, year, month) { -%>
<% if (!dir) return -%>
<h3>
<a href="/posts/<%= year %>/<%= pad(month) %>"><%= _months[month - 1] %></a>
</h3>
<ul class="archive">
<% var posts = sortPosts(dir) -%>
<% for (var i in posts) { -%>
<% var post = posts[i] -%>
<% if (post.hidden) continue -%>
<li>
<% if (post.link) { -%>
<a href="<%= post.url %>">&rarr; <%= post.title %></a>
<% } else { -%>
<a href="<%= post.url %>"><%= post.title %></a>
<% } -%>
<time><%= formatDate(1000 * post.timestamp) %></time>
</li>
<% } -%>
</ul>
<% } -%>
<% var year = current.path[1] %>
<div class="container">
<h2>
<%= year %>
</h2>
<% for (var month = 12; month >= 1; month--) { -%>
<% posts(public.posts[year][pad(month)], year, month) -%>
<% } -%>
</div>

View file

@ -52,7 +52,7 @@ class MetaWeblogHandler
git_pull
FileUtils.mkdir_p(post_dir)
ensure_post_dir_exists(post_dir)
post_filename = File.join(post_dir, "#{slug}.md")
File.open(post_filename, 'w') do |f|
@ -92,6 +92,22 @@ class MetaWeblogHandler
n.to_i < 10 ? "0#{n}" : "#{n}"
end
def ensure_post_dir_exists(post_dir)
FileUtils.mkdir_p(post_dir)
monthly_index_filename = File.join(post_dir, 'index.ejs')
unless File.exists?(monthly_index_filename)
source = File.join(post_dir, '../../2006/02/index.ejs')
FileUtils.cp(source, monthly_index_filename)
end
yearly_index_filename = File.join(post_dir, '../index.ejs')
unless File.exists?(yearly_index_filename)
source = File.join(post_dir, '../../2006/index.ejs')
FileUtils.cp(source, yearly_index_filename)
end
end
def read_post_data(dir)
post_data_filename = File.join(dir, '_data.json')
if File.exists?(post_data_filename)