Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Lots of improvements
Browse files Browse the repository at this point in the history
-- Add forgery for fake data generation during template creation
-- Add sitemap_generator gem to help with creating XML sitemaps
-- Add automatic sitemap generation on successful build via custom
   extension
-- Add wrapped layout for blog articles
-- Compress js and css during build
-- Add article partial
-- Add pagination partial
-- Refactor index, calendar, tag templates to use pagination and
   article partials
-- Use CDN for jquery
  • Loading branch information
mattolson committed Feb 20, 2013
1 parent 4447e1d commit 8d6addb
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 84 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ gem "middleman-blog", "~> 3.1.1"
gem "kramdown"
gem "builder", "~> 3.0.0"
gem "compass"
gem "zurb-foundation", :github => 'zurb/foundation' # until 3.2.6 comes out
gem "zurb-foundation", :github => 'zurb/foundation', :branch => 'master' # until 3.2.6 comes out
gem "forgery"
gem "sitemap_generator"
8 changes: 7 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
GIT
remote: git://github.com/zurb/foundation.git
revision: 9e0fc7b116d6f63824c1e6b10b06f0b9505fd4e3
revision: d98e0ab62f5f9ed8457d22b547b78d6b6b1bdcf7
branch: master
specs:
zurb-foundation (3.2.5)
compass (>= 0.12.2)
Expand All @@ -27,6 +28,7 @@ GEM
execjs (1.4.0)
multi_json (~> 1.0)
ffi (1.3.1)
forgery (0.5.0)
fssm (0.2.10)
haml (3.1.7)
hike (1.2.1)
Expand Down Expand Up @@ -102,6 +104,8 @@ GEM
rack (~> 1.4)
rack-protection (~> 1.3)
tilt (~> 1.3, >= 1.3.3)
sitemap_generator (3.4)
builder
sprockets (2.4.5)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -126,7 +130,9 @@ PLATFORMS
DEPENDENCIES
builder (~> 3.0.0)
compass
forgery
kramdown
middleman (~> 3.0.11)
middleman-blog (~> 3.1.1)
sitemap_generator
zurb-foundation!
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ This is a template for the excellent [Middleman](http://middlemanapp.com/) stati
Clone into `~/.middleman` (you'll have to create it if it doesn't exist). You can then use it with the `--template` flag on `middleman init`.

1. `mkdir -p ~/.middleman`
1. `git clone git://github.com/mattolson/middleman-zurb-template.git ~/.middleman/zurb-foundation`
2. `middleman init my_new_project --template=zurb-foundation`
2. `git clone git://github.com/mattolson/middleman-zurb-template.git ~/.middleman/zurb-foundation`
3. `middleman init my_new_project --template=zurb-foundation`
4. `cd my_new_project && bundle install`
5. `middleman server`

For more help follow [Middleman's project template instructions](http://middlemanapp.com/getting-started/) or feel to ask me on [Twitter](http://twitter.com/ahbiscuits).

11 changes: 6 additions & 5 deletions config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
blog.permalink = ":year/:month/:day/:title.html"
blog.sources = ":year-:month-:day-:title.html"
blog.taglink = "tags/:tag.html"
blog.layout = "layout"
blog.layout = "article"
blog.summary_separator = /(READMORE)/
blog.summary_length = 250
blog.year_link = ":year.html"
Expand Down Expand Up @@ -77,17 +77,18 @@
# end
# end

# Generate sitemap after build
activate :sitemap_generator

set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'

# Build-specific configuration
configure :build do
# For example, change the Compass output style for deployment
# activate :minify_css

# Minify Javascript on build
# activate :minify_javascript
activate :minify_css
activate :minify_javascript

# Enable cache buster
# activate :cache_buster
Expand Down
21 changes: 21 additions & 0 deletions extensions/sitemap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'sitemap_generator'

module GoogleSitemapGenerator
class << self
def registered(app)
app.after_build do |builder|
app_sitemap = sitemap # avoid name conflict
SitemapGenerator::Sitemap.default_host = "http://mattolson.com"
SitemapGenerator::Sitemap.create(:public_path => 'build', :verbose => true) do
app_sitemap.resources.each do |r|
add(r.url) if r.ext == '.html'
end
end
end
end
alias :included :registered
end
end

::Middleman::Extensions.register(:sitemap_generator, GoogleSitemapGenerator)

50 changes: 50 additions & 0 deletions source/blog/_article.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<div class="row">
<article class="nine columns">
<h3>
<% if digest %>
<%= link_to article.title, article %>
<% else %>
<%= article.title %>
<% end %>
</h3>

<% if digest %>
<%= article.summary %>
<% else %>
<%= article.body %>
<% end %>
<% if digest && article.summary.length < article.body.length %>
<%= link_to 'Read more &rarr;', article.url, :class => 'secondary button radius' %>
<% end %>
<% unless digest %>
<ul class="read_next">
<li><%= article.previous_article ? link_to("&laquo; #{article.previous_article.title}", article.previous_article) : "&nbsp;" %></li>
<li><%= article.next_article ? link_to("#{article.next_article.title} &raquo;", article.next_article) : "&nbsp;" %></li>
</ul>

<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
<% end %>
</article>
<aside class="three columns">
<ul class="credit">
<li class="time">Posted on <time datetime="<%= article.date.strftime('%Y-%m-%d') %>"><%= article.date.strftime('%A %b %e, %Y') %></time></li>
</ul>
<ul class="tags">
<% article.tags.each do |tag| %>
<li><%= link_to tag, tag_path(tag), :class => 'tiny button secondary round' %></li>
<% end %>
</ul>
</aside>
</div>
27 changes: 27 additions & 0 deletions source/blog/_pagination.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<% if paginate && num_pages > 1 %>
<div class="pagination-centered">
<ul class="pagination">
<% if prev_page %>
<li class="arrow<%= prev_page.nil? ? ' unavailable' : '' %>"><%= link_to '&laquo; Newer', prev_page %></li>
<% end %>
<%
(1..num_pages).each do |i|
if i == page_number %>
<li class="current unavailable"><%= link_to "#{i}", '#' %></li>
<% else
p = nil
if i < page_number
(i...page_number).each do p = p ? p.metadata[:locals]['prev_page'] : prev_page; end
else
(page_number...i).each do p = p ? p.metadata[:locals]['next_page'] : next_page; end
end
%>
<li><%= link_to "#{i}", p && p.url %></li>
<% end %>
<% end %>
<% if next_page %>
<li class="arrow<%= next_page.nil? ? ' unavailable' : '' %>"><%= link_to 'Older &raquo;', next_page %></li>
<% end %>
</ul>
</div>
<% end %>
20 changes: 7 additions & 13 deletions source/blog/calendar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,16 @@ pageable: true
<% end %>
</h1>

<% if paginate %>
<p>Page <%= page_number %> of <%= num_pages %></p>

<% if prev_page %>
<p><%= link_to 'Previous page', prev_page %></p>
<% end %>
<% end %>

<ul>
<% page_articles.each_with_index do |article, i| %>
<li><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></li>
<% end %>
</ul>

<% if paginate %>
<% if next_page %>
<p><%= link_to 'Next page', next_page %></p>
<% end %>
<% end %>
<%= partial '/blog/pagination', :locals => {
:paginate => paginate,
:next_page => next_page,
:prev_page => prev_page,
:num_pages => num_pages,
:page_number => page_number
} %>
35 changes: 17 additions & 18 deletions source/blog/tag.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
---
pageable: true
per_page: 12
---
<h1>Articles tagged '<%= tagname %>'</h1>

<% if paginate %>
<p>Page <%= page_number %> of <%= num_pages %></p>

<% if prev_page %>
<p><%= link_to 'Previous page', prev_page %></p>
<% end %>
<% end %>
<ul class="breadcrumbs">
<li><a href="/">Home</a></li>
<li class="current"><a href="<%= tag_path tagname %>"><%= tagname %></a></li>
</ul>

<ul>
<div class="articles">
<% page_articles.each_with_index do |article, i| %>
<li><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></li>
<% if i > 0 %>
<hr />
<% end %>
<%= partial '/blog/article', :locals => {:article => article, :digest => true} %>
<% end %>
</ul>
</div>

<% if paginate %>
<% if next_page %>
<p><%= link_to 'Next page', next_page %></p>
<% end %>
<% end %>
<%= partial '/blog/pagination', :locals => {
:paginate => paginate,
:next_page => next_page,
:prev_page => prev_page,
:num_pages => num_pages,
:page_number => page_number
} %>
30 changes: 14 additions & 16 deletions source/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
---
pageable: true
per_page: 10
---
<% page_articles.each_with_index do |article, i| %>
<h3><%= link_to article.title, article %></h3>
<p><%= article.date.strftime('%b %e') %></p>
<p><%= article.summary %></p>
<% end %>
<% if paginate %>
<% if prev_page %>
<p><%= link_to 'Previous page', prev_page %></p>
<div class="articles">
<% page_articles.each_with_index do |article, i| %>
<% if i > 0 %>
<hr />
<% end %>
<%= partial '/blog/article', :locals => {:article => article, :digest => true} %>
<% end %>
</div>

<p>Page <%= page_number %> of <%= num_pages %></p>

<% if next_page %>
<p><%= link_to 'Next page', next_page %></p>
<% end %>
<% end %>
<%= partial '/blog/pagination', :locals => {
:paginate => paginate,
:next_page => next_page,
:prev_page => prev_page,
:num_pages => num_pages,
:page_number => page_number
} %>
1 change: 0 additions & 1 deletion source/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//= require jquery
//= require foundation
//= require jquery.fancybox
//= require jquery.fancybox-media
Expand Down
3 changes: 3 additions & 0 deletions source/layouts/article.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% wrap_layout :layout do %>
<%= partial '/blog/article', :locals => {:article => current_article, :digest => false} %>
<% end %>
32 changes: 5 additions & 27 deletions source/layouts/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,7 @@
<!-- Main page container -->
<div class="row">
<div class="twelve columns">
<div class="eight columns">
<%= yield %>
</div>
<div class="four columns">
<aside>
<h3>Recent Articles</h3>
<ol>
<% blog.articles[0...10].each do |article| %>
<li><a href="<%= article.url %>"><%= article.title %></a> <span><%= article.date.strftime('%b %e') %></span></li>
<% end %>
</ol>

<h3>Tags</h3>
<ol>
<% blog.tags.each do |tag, articles| %>
<li><a href="<%= tag_path tag %>"><%= tag %> (<%= articles.size %>)</a></li>
<% end %>
</ol>

<h3>By Year</h3>
<ol>
<% blog.articles.group_by {|a| a.date.year }.each do |year, articles| %>
<li><a href="<%= blog_year_path year %>"><%= year %> (<%= articles.size %>)</a></li>
<% end %>
</ol>
</aside>
</div>
<%= yield %>
</div>
</div>

Expand Down Expand Up @@ -139,6 +113,10 @@
</div>
<![endif]-->

<!-- jQuery -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/jquery.js"><\/script>');</script>

<!-- Javascript -->
<%= javascript_include_tag "application" %>
<%= yield_content :javascripts %>
Expand Down
Loading

0 comments on commit 8d6addb

Please sign in to comment.