put multiple posts on the home page

This commit is contained in:
Sami Samhuri 2014-03-09 22:46:12 -07:00
parent 6a9b6da4d5
commit 1d0e7fd36c
4 changed files with 176 additions and 46 deletions

View file

@ -31,13 +31,13 @@ class Blag
end end
def generate! def generate!
generate_latest_post_json generate_latest_posts_json
generate_rss generate_rss
end end
def generate_latest_post_json def generate_latest_posts_json
post = latest_post data['posts'] = latest_posts.map do |post|
data['latest'] = { {
title: post['title'], title: post['title'],
date: post['date'], date: post['date'],
timestamp: post['timestamp'], timestamp: post['timestamp'],
@ -48,6 +48,7 @@ class Blag
styles: post['styles'], styles: post['styles'],
body: post['body'] body: post['body']
}.delete_if { |k, v| v.nil? } }.delete_if { |k, v| v.nil? }
end
json = JSON.pretty_generate data json = JSON.pretty_generate data
File.open(data_file, 'w') { |f| f.puts json } File.open(data_file, 'w') { |f| f.puts json }
end end
@ -56,8 +57,8 @@ class Blag
File.open(rss_file, 'w') { |f| f.puts feed_xml.target! } File.open(rss_file, 'w') { |f| f.puts feed_xml.target! }
end end
def latest_post def latest_posts(n = @num_posts)
posts.first posts.first(n)
end end
def find_post dir, slug def find_post dir, slug

File diff suppressed because one or more lines are too long

View file

@ -326,6 +326,8 @@ body.projects:not(.index) .container {
article { article {
word-wrap: break-word;
header { header {
h2 { h2 {
@ -351,6 +353,7 @@ article {
blockquote { blockquote {
margin-left: 6%; margin-left: 6%;
font-family: 'Helvetica Neue', 'Verdana', 'Roboto', sans-serif;
font-style: italic; font-style: italic;
color: lighten(@text, 15%); color: lighten(@text, 15%);
} }

View file

@ -1,20 +1,35 @@
<% var post = public._data.latest -%> <% var posts = public._data.posts -%>
<% for (var i in posts) { -%>
<% var post = posts[i] -%>
<% if (post.link) { -%>
<% if (post.link) { -%>
<article> <article>
<header> <header>
<h2><a href="<%= post.link %>"><%= post.title %></a></h2> <h2><a href="<%= post.link %>"><%= post.title %></a></h2>
<time><%= post.date %></time> <time><%= post.date %></time>
</header> </header>
<%- post.body %> <%- partial(post.url) %>
<p><a class="permalink" href="<%= post.url %>">&infin;</a></p> <p><a class="permalink" href="<%= post.url %>">&infin;</a></p>
</article> </article>
<% } else { -%>
<% } else { -%>
<article> <article>
<header> <header>
<h2><a href="<%= post.url %>"><%= post.title %></a></h2> <h2><a href="<%= post.url %>"><%= post.title %></a></h2>
<time><%= post.date %></time> <time><%= post.date %></time>
</header> </header>
<%- post.body %> <%- partial(post.url) %>
</article> </article>
<% } -%>
<% if (i < posts.length - 1) { -%>
<div class="row clearfix">
<p class="fin"><i class="fa fa-code"></i></p>
</div>
<% } -%>
<% } -%> <% } -%>