This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rules
274 lines (231 loc) · 7.71 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/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.binary? && item[:title]
item[:kind] = "article"
item[:layout] = "post"
item[:comments] = true
item[:custom_url_in_feed] = item[:link] if item[:link]
if !item[:created_at] && m = /blog\/(\d{4}-\d{2}-\d{2})/.match(item.identifier)
item[:created_at] = m[1]
end
# Explicitly put author tags on blog posts.
# This is so the feed generator generates author information for each entry,
# because not all RSS readers show global author names.
if !item[:author_name] && !item[:author_uri]
item[:author_name] = @config[:author_name]
item[:author_uri] = @config[:author_uri]
end
end
unless item.binary? || item[:header_image]
if item.identifier.without_ext.end_with?('index')
parent_path = Pathname.new(item.identifier).parent
else
parent_path = Pathname.new(item.identifier.without_ext)
end
# FIXME: Hard coding content is probably ugly
item[:header_image] = %w(jpg png)
.map { |ext| parent_path / "header.#{ext}"}
.find { |p| File.exist?(File.join("content", p)) }
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
if @config[:site_subtitle]
title = "#{@config[:site_title]} | #{@config[:site_subtitle]}"
else
title = "#{@config[:site_title]}"
end
id = "/index.html"
else
title = "Archive (posts #{first} to #{last})"
id = "/blog/page#{i+1}.html"
end
@items.create("<%= render '/blog_page.*', item_id: #{i} %>", {
title: title,
created_at: DateTime.now,
paged: true,
kind: "article_list",
body_classes: ["blog"] + (i == 0 ? ["infinite-scroll"] : [])
}, id)
end
# Add top feed to all items
@items.each { |item| item[:feed] = (item[:feed] || "/feed.xml") }
# Add tag pages (and their feed)
all_article_tags.each do |name|
path = "/blog/tag/#{slugify(name)}"
articles = "articles_with_tag(\"#{name}\")"
attributes = {
title: "Tag: #{name}",
created_at: DateTime.now,
kind: "article_list",
feed: "/feed.xml",
tag: "#{name}",
body_classes: ["archive", "tag"]
}
# Add feed for specific topics
if %w(jabber).include?(name.downcase)
attributes[:feed] = "#{path}/feed.xml"
@items.create("<%= atom_feed title: \"#{@config[:site_title]} | #{name}\", author_name: @config[:author_name], author_uri: @config[:author_uri], articles: #{articles}, content_proc: lambda { |a| a.compiled_content(rep: :linked_excerpt) }, limit: 10 %>", {kind: "feed"}, "#{path}/feed.xml")
end
@items.create("<%= render '/archive_page.*', posts: #{articles} %>", attributes, "#{path}.html")
end
# Hide some items
@items.each do |item|
item[:is_hidden] = true if %r<^/static/google\w{16}>.match(item.identifier.to_s) || item[:link]
end
end
################################################################################
# XML files (Feeds, Sitemap)
################################################################################
compile '/**/{feed,sitemap}.xml' do
filter :erb
filter :git_link_filter
write item.identifier.to_s
end
################################################################################
# Blog
################################################################################
# Excerpts with a "Read More ..." link
compile '/blog/**/*.md', rep: :linked_excerpt do
filter :rdiscount, extensions: [:smart]
filter :more_filter
write nil
end
compile '/blog/**/*.md', rep: :feed_excerpt do
filter :rdiscount, extensions: [:smart, :footnotes]
filter :more_filter
filter :git_link_filter
filter :absolutify_urls, base: @config[:base_url]
write nil
end
route '/blog/**/*' do
if item.binary? or !item[:title]
item.identifier.to_s
elsif item.identifier.without_ext.end_with?('index')
item.identifier.without_ext.gsub(/\d\d\d\d-\d\d-\d\d-/, '') + '.html'
else
item.identifier.without_ext.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
################################################################################
# Avatar
################################################################################
# Libravatar avatars
@config[:avatars][:email].each do |avatar|
compile "/avatar.*", rep: avatar + "_sha256" do
write "/avatar/" + Digest::SHA256.hexdigest(avatar.strip.downcase)
end
compile "/avatar.*", rep: avatar + "_md5" do
write "/avatar/" + Digest::MD5.hexdigest(avatar.strip.downcase)
end
end
if @config[:avatars] && @config[:avatars][:openid]
@config[:avatars][:openid].each do |avatar|
compile "/avatar.*", rep: avatar do
write "/avatar/" + Digest::SHA256.hexdigest(avatar.strip.downcase)
end
end
end
# Simple avatar
route "/avatar.*" do
"/avatar/avatar.jpg"
end
################################################################################
# Favicon
################################################################################
route '/favicon/**' do
item.identifier.to_s.sub(/\A\/favicon/, '')
end
################################################################################
# Files that don't need processing
################################################################################
compile '/static/**/*' do
write item.identifier.to_s.sub(/\A\/static/, '')
end
################################################################################
################################################################################
# Default handling
################################################################################
compile '/**/*.{md,html}' do
filter :erb
if item.identifier.to_s.end_with?(".md")
filter :rdiscount, extensions: [:smart, :footnotes]
end
snapshot :filtered_contents
filter :colorize_syntax, coderay: { tab_width: 2 }, syntax: :html, default_colorizer: :rouge
if item[:layout]
layout "/#{item[:layout]}.*"
end
layout '/default.*' unless item[:no_default_layout]
filter :more_filter, mode: :replace
filter :git_link_filter
filter :image_size
end
compile '/**/*.css' do
filter :erb
filter :absolutify_css_urls
filter :minify_css
end
compile '/**/*.js.erb' do
filter :erb
filter :uglify_js
write item.identifier.without_ext
end
compile '/**/*.js' do
filter :uglify_js
end
compile '/**/*.asc' do
filter :erb
end
compile '/**/*.{png,jpg}' do
filter :compress_image
end
compile '/**/*' do
end
route '/**/index.{html,md}' do
item.identifier.without_ext + '.html'
end
route '/**/*.{html,md}' do
item.identifier.without_ext + '/index.html'
end
route '/**/*' do
item.identifier.to_s
end
layout '/**/*.haml', :haml
layout '/**/*.html', :erb