mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-03-25 09:05:47 +00:00
add yearly and monthly archive indexes
This commit is contained in:
parent
4d23c27584
commit
24f60083a2
46 changed files with 199 additions and 32 deletions
|
|
@ -68,6 +68,7 @@ class Blag
|
||||||
def posts
|
def posts
|
||||||
@posts ||= begin
|
@posts ||= begin
|
||||||
Dir[File.join(@dir, 'posts/20*/*')].map do |dir|
|
Dir[File.join(@dir, 'posts/20*/*')].map do |dir|
|
||||||
|
next unless dir =~ /\/\d\d$/
|
||||||
json = File.read File.join(dir, '_data.json')
|
json = File.read File.join(dir, '_data.json')
|
||||||
data = JSON.parse json
|
data = JSON.parse json
|
||||||
prefix = dir.sub(@dir, '')
|
prefix = dir.sub(@dir, '')
|
||||||
|
|
@ -85,7 +86,7 @@ class Blag
|
||||||
post['rfc822'] = Time.at(post['timestamp']).rfc822
|
post['rfc822'] = Time.at(post['timestamp']).rfc822
|
||||||
post
|
post
|
||||||
end
|
end
|
||||||
end.flatten.sort_by { |p| -p['timestamp'] }.first(@num_posts)
|
end.flatten.compact.sort_by { |p| -p['timestamp'] }.first(@num_posts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,10 +94,10 @@
|
||||||
<a class="permalink" href="<%= url %>">∞</a>
|
<a class="permalink" href="<%= url %>">∞</a>
|
||||||
</header>
|
</header>
|
||||||
<%- yield %>
|
<%- yield %>
|
||||||
<div class="row clearfix">
|
|
||||||
<p class="fin clearfix"><i class="fa fa-code"></i></p>
|
|
||||||
</div>
|
|
||||||
</article>
|
</article>
|
||||||
|
<div class="row clearfix">
|
||||||
|
<p class="fin clearfix"><i class="fa fa-code"></i></p>
|
||||||
|
</div>
|
||||||
<% } else if (typeof date != 'undefined') { -%>
|
<% } else if (typeof date != 'undefined') { -%>
|
||||||
<article class="container">
|
<article class="container">
|
||||||
<header>
|
<header>
|
||||||
|
|
@ -105,25 +105,20 @@
|
||||||
<time><%= date %></time>
|
<time><%= date %></time>
|
||||||
</header>
|
</header>
|
||||||
<%- yield %>
|
<%- yield %>
|
||||||
<div class="row clearfix">
|
|
||||||
<p class="fin"><i class="fa fa-code"></i></p>
|
|
||||||
</div>
|
|
||||||
</article>
|
</article>
|
||||||
|
<div class="row clearfix">
|
||||||
|
<p class="fin"><i class="fa fa-code"></i></p>
|
||||||
|
</div>
|
||||||
<% } else if (typeof title != 'undefined') { -%>
|
<% } else if (typeof title != 'undefined') { -%>
|
||||||
<article class="container">
|
<article class="container">
|
||||||
<h2><%= title %></h2>
|
<h2><%= title %></h2>
|
||||||
<%- yield %>
|
<%- yield %>
|
||||||
<div class="row clearfix">
|
|
||||||
<p class="fin"><i class="fa fa-code"></i></p>
|
|
||||||
</div>
|
|
||||||
</article>
|
</article>
|
||||||
|
<div class="row clearfix">
|
||||||
|
<p class="fin"><i class="fa fa-code"></i></p>
|
||||||
|
</div>
|
||||||
<% } else { -%>
|
<% } else { -%>
|
||||||
<article class="container">
|
<%- yield %>
|
||||||
<%- yield %>
|
|
||||||
<div class="row clearfix">
|
|
||||||
<p class="fin"><i class="fa fa-code"></i></p>
|
|
||||||
</div>
|
|
||||||
</article>
|
|
||||||
<% } -%>
|
<% } -%>
|
||||||
|
|
||||||
<footer class="container">
|
<footer class="container">
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,9 @@
|
||||||
<% function posts(dir, year) { -%>
|
<% function posts(dir, year) { -%>
|
||||||
<% if (!dir) return -%>
|
<% if (!dir) return -%>
|
||||||
|
|
||||||
<h3><%= year %></h3>
|
<h3>
|
||||||
|
<a href="/posts/<%= year %>"><%= year %></a>
|
||||||
|
</h3>
|
||||||
|
|
||||||
<% for (var month = 12; month >= 1; month--) { -%>
|
<% for (var month = 12; month >= 1; month--) { -%>
|
||||||
<% var monthDir = dir[pad(month)] -%>
|
<% var monthDir = dir[pad(month)] -%>
|
||||||
|
|
@ -38,7 +40,7 @@
|
||||||
<% } else { -%>
|
<% } else { -%>
|
||||||
<a href="<%= post.url %>"><%= post.title %></a>
|
<a href="<%= post.url %>"><%= post.title %></a>
|
||||||
<% } -%>
|
<% } -%>
|
||||||
<span class="date"><%= formatDate(1000 * post.timestamp) %></span>
|
<time><%= formatDate(1000 * post.timestamp) %></time>
|
||||||
</li>
|
</li>
|
||||||
<% } -%>
|
<% } -%>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
|
|
@ -257,12 +257,11 @@ ul.archive {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.date {
|
time {
|
||||||
font-size: 80%;
|
font-size: 80%;
|
||||||
padding-left: 0.5rem;
|
padding-left: 0.5rem;
|
||||||
color: lighten(@text, 30%);
|
color: lighten(@text, 30%);
|
||||||
// float: right;
|
}
|
||||||
} /* .date */
|
|
||||||
|
|
||||||
} /* li */
|
} /* 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 {
|
blockquote {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
<div class="container">
|
||||||
<% var posts = public._data.posts -%>
|
<% var posts = public._data.posts -%>
|
||||||
<% for (var i in posts) { -%>
|
<% for (var i in posts) { -%>
|
||||||
|
|
||||||
|
|
@ -26,10 +27,9 @@
|
||||||
|
|
||||||
<% } -%>
|
<% } -%>
|
||||||
|
|
||||||
<% if (i < posts.length - 1) { -%>
|
<div class="row clearfix">
|
||||||
<div class="row clearfix">
|
<p class="fin"><i class="fa fa-code"></i></p>
|
||||||
<p class="fin"><i class="fa fa-code"></i></p>
|
</div>
|
||||||
</div>
|
|
||||||
<% } -%>
|
|
||||||
|
|
||||||
<% } -%>
|
<% } -%>
|
||||||
|
</div>
|
||||||
1
public/posts/2006/02/index.ejs
Normal file
1
public/posts/2006/02/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2006/03/index.ejs
Normal file
1
public/posts/2006/03/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2006/04/index.ejs
Normal file
1
public/posts/2006/04/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2006/05/index.ejs
Normal file
1
public/posts/2006/05/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2006/06/index.ejs
Normal file
1
public/posts/2006/06/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2006/07/index.ejs
Normal file
1
public/posts/2006/07/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2006/08/index.ejs
Normal file
1
public/posts/2006/08/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2006/09/index.ejs
Normal file
1
public/posts/2006/09/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2006/12/index.ejs
Normal file
1
public/posts/2006/12/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2006/index.ejs
Normal file
1
public/posts/2006/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../_year') %>
|
||||||
1
public/posts/2007/03/index.ejs
Normal file
1
public/posts/2007/03/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2007/04/index.ejs
Normal file
1
public/posts/2007/04/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2007/05/index.ejs
Normal file
1
public/posts/2007/05/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2007/06/index.ejs
Normal file
1
public/posts/2007/06/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2007/07/index.ejs
Normal file
1
public/posts/2007/07/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2007/08/index.ejs
Normal file
1
public/posts/2007/08/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2007/09/index.ejs
Normal file
1
public/posts/2007/09/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2007/10/index.ejs
Normal file
1
public/posts/2007/10/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2007/index.ejs
Normal file
1
public/posts/2007/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../_year') %>
|
||||||
1
public/posts/2008/01/index.ejs
Normal file
1
public/posts/2008/01/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2008/02/index.ejs
Normal file
1
public/posts/2008/02/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2008/03/index.ejs
Normal file
1
public/posts/2008/03/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2008/index.ejs
Normal file
1
public/posts/2008/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../_year') %>
|
||||||
1
public/posts/2009/11/index.ejs
Normal file
1
public/posts/2009/11/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2009/index.ejs
Normal file
1
public/posts/2009/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../_year') %>
|
||||||
1
public/posts/2010/01/index.ejs
Normal file
1
public/posts/2010/01/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2010/11/index.ejs
Normal file
1
public/posts/2010/11/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2010/index.ejs
Normal file
1
public/posts/2010/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../_year') %>
|
||||||
1
public/posts/2011/11/index.ejs
Normal file
1
public/posts/2011/11/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2011/12/index.ejs
Normal file
1
public/posts/2011/12/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2011/index.ejs
Normal file
1
public/posts/2011/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../_year') %>
|
||||||
1
public/posts/2012/01/index.ejs
Normal file
1
public/posts/2012/01/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2012/index.ejs
Normal file
1
public/posts/2012/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../_year') %>
|
||||||
1
public/posts/2013/03/index.ejs
Normal file
1
public/posts/2013/03/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2013/09/index.ejs
Normal file
1
public/posts/2013/09/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2013/index.ejs
Normal file
1
public/posts/2013/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../_year') %>
|
||||||
1
public/posts/2014/02/index.ejs
Normal file
1
public/posts/2014/02/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../../_month') %>
|
||||||
1
public/posts/2014/index.ejs
Normal file
1
public/posts/2014/index.ejs
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<%- partial('../_year') %>
|
||||||
52
public/posts/_month.ejs
Normal file
52
public/posts/_month.ejs
Normal 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 %>">→ <%= post.title %></a></h2>
|
||||||
|
<time><%= post.date %></time>
|
||||||
|
<a class="permalink" href="<%= post.url %>">∞</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
64
public/posts/_year.ejs
Normal 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 %>">→ <%= 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>
|
||||||
|
|
@ -52,7 +52,7 @@ class MetaWeblogHandler
|
||||||
|
|
||||||
git_pull
|
git_pull
|
||||||
|
|
||||||
FileUtils.mkdir_p(post_dir)
|
ensure_post_dir_exists(post_dir)
|
||||||
|
|
||||||
post_filename = File.join(post_dir, "#{slug}.md")
|
post_filename = File.join(post_dir, "#{slug}.md")
|
||||||
File.open(post_filename, 'w') do |f|
|
File.open(post_filename, 'w') do |f|
|
||||||
|
|
@ -92,6 +92,22 @@ class MetaWeblogHandler
|
||||||
n.to_i < 10 ? "0#{n}" : "#{n}"
|
n.to_i < 10 ? "0#{n}" : "#{n}"
|
||||||
end
|
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)
|
def read_post_data(dir)
|
||||||
post_data_filename = File.join(dir, '_data.json')
|
post_data_filename = File.join(dir, '_data.json')
|
||||||
if File.exists?(post_data_filename)
|
if File.exists?(post_data_filename)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue