-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rules
executable file
·262 lines (214 loc) · 5.85 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
#!/usr/bin/env ruby
# coding: utf-8
# A few helpful tips about the Rules file:
#
# * The string given to #compile and #route are matching patterns for
# identifiers--not for paths. Therefore, you can’t match on extension.
#
# * The order of rules is important: for each item, only the first matching
# rule is applied.
#
# * Item identifiers start and end with a slash (e.g. “/about/” for the file
# “content/about.html”). To select all children, grandchildren, … of an
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
# because “*” matches zero or more characters.
KRAMDOWN_OPTS = { auto_ids: true, input: 'GFM', syntax_highlighter: 'rouge' }
BYPASS_FILES = %w(404.html crossdomain.xml humans.txt robots.txt googlebd82924855df6b5d.html) unless defined?(BYPASS_FILES)
# from https://github.com/mgutz/nanoc3_blog/blob/master/Rules
preprocess do
config[:env] = ENV['NANOC_ENV'] ||= 'development'
config[:is_deploying] = ['production', 'staging'].include?(ENV['NANOC_ENV'])
config[:htpasswd_path] = ENV['HTPASSWD_PATH']
# authors may unpublish items by setting meta attribute `publish: false`
items.delete_if { |item| item[:publish] == false }
tags("article", :en).each do |tag, mtime|
@items.create(
"",
{
:title => %Q{Posts tagged “#{tag}”},
:tag => tag.to_s,
:mtime => mtime,
:kind => "tag",
:lang => :en,
},
"/posts/tags/#{Tag::clean_name(tag)}"
)
end
tags("article", :de).each do |tag, mtime|
@items.create(
"",
{
:title => %Q{Beiträge mit Schlagwort “#{tag}”},
:tag => tag.to_s,
:mtime => mtime,
:kind => "tag",
:lang => :de,
},
"/de/posts/tags/#{Tag::clean_name(tag)}"
)
end
# TODO: Add Year/Month overviews for all languages
years, months = Post::years_and_months(posts())
years.each do |year, mtime|
@items.create(
"<%= render '/_posts_per_time.*', :from => '#{year}-01-01', :to => '#{year}-12-31' %>",
{
:title => %Q{Posts from #{year}},
:mtime => mtime
},
"/posts/#{year}"
)
end
months.each do |monthdata, mtime|
month = Month.new(monthdata)
@items.create(
"<%= render '/_posts_per_time.*', :from => '#{month.first_day}', :to => '#{month.last_day}' %>",
{
:title => %Q{Posts from #{month.title} #{month.year}},
:mtime => mtime
},
month.post_url
)
end
end
BYPASS_FILES.each do |file|
passthrough "/#{file}"
end
ignore '/**/_*' # don't compile and route partials (used for SASS, JS)
compile '/css/fonts/*' do
write item.identifier
end
compile '/css/vendor/*' do
filter :erb # Use erb to enable timestamps and author information and such.
filter :dart_sass, syntax: 'scss'
write item.identifier
end
compile '/css/**/*' do
filter :erb # Use erb to enable timestamps and author information and such.
filter :dart_sass, syntax: 'scss'
write item.identifier.without_ext + '-' + fingerprint('/css/*') + ".css"
end
compile '/js/vendor/*' do
write item.identifier
end
compile '/js/**/*' do
filter :concat_js
filter :uglify_js if config[:is_deploying]
write item.identifier.without_ext + '-' + fingerprint('/js/*') + '.js'
end
compile '/sitemap.*' do
filter :erb
write item.identifier.to_s
end
compile '/htaccess.*' do
filter :erb
write '/.htaccess'
end
#
# Blog
#
compile '**/feed.atom' do
filter :erb
write item.identifier.to_s
end
compile '/posts/tags/*.*' do
filter :erb
filter :kramdown, KRAMDOWN_OPTS
layout '/plain.*'
end
compile %r{^/(de/)?posts/tags/.*?} do
filter :erb
layout '/tags.*'
end
compile %r{^/posts/\d{4}(/\d{2})?$} do
filter :erb
layout '/plain.*'
end
compile '/posts/*' do
filter :erb
filter :kramdown, KRAMDOWN_OPTS
layout '/plain.*'
filter :add_toc
end
compile '/overview/index.md' do
filter :erb
filter :kramdown, KRAMDOWN_OPTS
layout '/plain.*'
filter :add_toc
end
compile '/posts/**/*' do
unless item.binary? # don’t filter binary items
filter :erb
filter :kramdown, KRAMDOWN_OPTS
layout '/blog.*'
filter :add_toc
end
end
#
# Misc content
#
compile '/**/*' do
if item.binary?
write item.identifier.to_s
next
end
case item[:extension]
when 'md', 'markdown', 'txt', 'text'
filter :erb
filter :kramdown, KRAMDOWN_OPTS
else
filter :erb
filter :typogruby
end
if item[:layout]
layout '/'+item[:layout]+'.*'
else
layout '/plain.*'
# layout 'default' # use if basic `section > h1` setting doesn't suffice
end
if item_has_toc?(item)
filter :add_toc
end
end
############################################################################
route '/404.*' do
item.identifier.without_ext + '.html'
end
route %r{^/(de/)?posts/.*?} do |_, custom_lang|
if item.binary?
id = item.identifier.components.last
post_id = item.identifier.components[-2]
"/posts/" + post_id + "/" + id
elsif item[:kind] == 'article'
if custom_path = item[:custom_path]
path = custom_path.chomp('/')
else
path = item.identifier.without_ext
.gsub(/\d{4}\/\d{2}\//, "") # remove date portion
.gsub(/\/index$/, "") # drop index file name
path = "/" + custom_lang.to_s + path if !custom_lang.nil?
end
path + '/index.html'
else # tags, date archives
path = item[:custom_path] || item.identifier.without_ext
if path =~ %r{/index$}
path + '.html'
else
path + '/index.html'
end
end
end
route '/**/*' do
if item.binary?
item.identifier.to_s
else
path = item[:custom_path] || item.identifier.without_ext
if path =~ %r{/index$}
path + '.html'
else
path + '/index.html'
end
end
end
############################################################################
layout '/**/*', :erb