forked from remko/blog-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rules
173 lines (144 loc) · 4.86 KB
/
Rules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env ruby
################################################################################
# Preprocessing
################################################################################
preprocess do
# Everything in my blog/ dir is an article.
# Derive the date from the filename (for Jekyll-style post naming)
@items.each do |item|
if /\/blog\/[^\/]*\/$/.match(item.identifier)
item[:kind] = "article"
item[:layout] = "post"
unless item[:created_at]
if m = /blog\/(\d\d\d\d-\d\d-\d\d)/.match(item.identifier)
item[:created_at] = m[1]
end
end
end
end
# Create paginated article pages (including front page)
articles_to_paginate = sorted_articles
article_groups = []
until articles_to_paginate.empty?
article_groups << articles_to_paginate.slice!(0..@config[:page_size]-1)
end
article_groups.each_with_index do |subarticles, i|
first = i*config[:page_size] + 1
last = (i+1)*config[:page_size]
if i == 0
title = "#{@config[:site_title]} | #{@config[:site_subtitle]}"
id = "/"
else
title = "Archive (posts #{first} to #{last})"
id = "/blog/page#{i+1}"
end
items << Nanoc::Item.new("<%= render 'include/blog_page', :item_id => #{i} %>", {
:title => title, :created_at => DateTime.now, :paged => true, :kind => "article_list" }, id)
end
# Add top feed to all items
@items.each do |item|
unless item[:feed]
item[:feed] = "/feed/"
end
end
# Add tag/category pages and their feed
["Category", "Tag"].zip([all_article_categories, all_article_tags]) do |(type, names)|
names.each do |name|
path = "/blog/#{type.downcase}/#{slugify(name)}"
articles = "articles_with_#{type.downcase}(\"#{name}\")"
items << Nanoc::Item.new("<%= render 'include/posts', :posts => #{articles} %>", {
:title => "#{type}: #{name}",
:created_at => DateTime.now,
:feed => "#{path}/feed/",
:kind => "article_list"
}, "#{path}")
items << Nanoc::Item.new("<%= atom_feed :title => \"#{@config[:site_title]} | #{name}\", :author_name => @config[:author_name], :author_uri => @config[:author_uri], :articles => #{articles}, :limit => 10 %>", {}, "#{path}/feed")
end
end
end
################################################################################
# Feeds
################################################################################
compile %r<.*/feed/> do
filter :erb
filter :git_link_filter
end
route %r<.*/feed/> do
item.identifier + 'index.xml'
end
################################################################################
# Blog
################################################################################
# Excerpts with a "Read More ..." link
compile '/blog/*', :rep => :linked_excerpt do
unless item.binary?
if item[:extension] == "md" or item[:extension] == "markdown"
filter :rdiscount, :extensions => [:smart]
end
filter :more_filter, :more_url => item.path
filter :git_link_filter
end
end
route '/blog/*', :rep => :linked_excerpt do
end
route '/blog/*' do
if item.binary? or item.identifier.end_with? "index"
item.identifier.chop + '.' + item[:extension]
else
item.identifier.gsub(/\d\d\d\d-\d\d-\d\d-/, '') + 'index.html'
end
end
################################################################################
# Git
################################################################################
# Create a representation for only the top and only the bottom of a dummy page.
# These will be included by CGit as header/footers.
compile '/git', :rep => :top do
layout 'default'
filter :split_filter, :delimiter => "<!-- CONTENT -->", :keep => :top
end
compile '/git', :rep => :bottom do
layout 'default'
filter :split_filter, :delimiter => "<!-- CONTENT -->", :keep => :bottom
end
route '/git', :rep => :top do
item.identifier + 'top.html'
end
route '/git', :rep => :bottom do
item.identifier + 'bottom.html'
end
################################################################################
# Files that need to be preserved as-is
################################################################################
compile '/blank' do
end
route '/blank' do
item.identifier.chop + '.' + item[:extension]
end
################################################################################
# Default handling
################################################################################
compile '*' do
unless item.binary?
filter :erb
if item[:extension] == "md" or item[:extension] == "markdown"
filter :rdiscount, :extensions => [:smart]
end
snapshot :filtered_contents
filter :colorize_syntax, :coderay => { :tab_width => 2 }
if item[:layout]
layout item[:layout]
end
layout 'default'
filter :git_link_filter
end
end
route '*' do
if item.binary? or item.identifier.end_with? "index"
item.identifier.chop + '.' + item[:extension]
else
# Write item with identifier /foo/ to /foo/index.html
item.identifier + 'index.html'
end
end
layout '*', :erb