-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rules
82 lines (66 loc) · 1.7 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
#!/usr/bin/env ruby
# frozen_string_literal: true
preprocess do
# ignore unpublished items
@items.delete_if { |item| item[:published] == false }
all_notes.each do |item|
slug = %r{\d{4}-\d{2}-\d{2}-([^/]+)}.match(item.identifier.without_exts).captures.first
item[:slug] = slug
end
end
compile '/assets/icons/**/*.svg' do
# TODO: optimize SVG (with svgo or something like that)
# no need to write/route such SVG, inlined within HTML
write nil
end
compile '/static/**/*' do
# don't filter or layout
end
# simply copy other assets
passthrough '/images/**/*'
compile '/notes/**/*' do
filter :fenced_code_block
filter :erb
filter :kramdown
filter :colorize_syntax, default_colorizer: :rouge
layout '/note.*'
layout '/base.*'
end
compile '/{rss,sitemap}.*' do
filter :erb
end
compile '/**/*' do
unless item.binary?
filter :erb
filter :kramdown
unless item[:layout] == 'none'
layout "/#{item[:layout]}.*" unless item[:layout].nil?
layout '/base.*'
end
end
end
route '/notes/**/*' do
raise "item #{item.identifier} doesn't have a slug" if item[:slug].nil?
slug = item[:slug]
post_date = Date.parse(item[:created_at].to_s)
month_2d = format('%02d', post_date.month)
day_2d = format('%02d', post_date.mday)
"/#{post_date.year}/#{month_2d}/#{day_2d}/#{slug}/index.html"
end
route '/static/**/*' do
item.identifier.to_s.delete_prefix('/static')
end
route '/{rss,sitemap}.*' do
item.identifier.to_s
end
route '/error/**/*' do
"#{item.identifier.without_ext.to_s.delete_prefix('/error')}.html"
end
route '/**/*' do
if item.binary?
item.identifier.to_s
else
"#{item.identifier.without_ext}.html"
end
end
layout '/**/*', :erb, trim_mode: '-'