-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rules
116 lines (96 loc) · 2.95 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
#!/usr/bin/env ruby
# 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.
preprocess do
# Anything with an explicit published: false should vanish
items.reject! {|item| item[:published] == false}
items.each do |item|
# Extract date from filename if present
item.identifier.match(%r{(/.*)?/(\d\d\d\d-\d\d-\d\d)-(.*)/}) do |md|
item.identifier = "#{md[1]}/#{md[3]}/"
item[:date] ||= md[2]
end
# Set the kind for certin subfolders
parts = item.identifier.split('/')
if parts.length > 2
case parts[1]
when 'posts'
item[:kind] ||= 'post'
when 'talks'
item[:kind] ||= 'talk'
end
end
# Parse the date if present
item[:date] = Date.parse(item[:date]) if item[:date].is_a?(String)
# Set the extra timestamps for the Blogging helper
item[:created_at] = item[:date].to_time if item[:date]
item[:updated_at] = item[:mtime] if item[:mtime]
# Convert the identifier into the title if not present
if item[:kind]
item[:title] ||= begin
words = item.identifier.split('/').last.split('-')
words.first.capitalize! # Always cap the first word
words.each {|word| word.capitalize! if word.length > 3}
words.join(' ')
end
end
end
end
compile '/static/*' do
# Don't touch static stuff
end
compile '/atom/' do
filter :erubis
end
compile '/sitemap/' do
filter :erubis
end
[
['*', rep: :default],
['/posts/*/', rep: :old_url], # Used to create a second copy at the old path
['/contact/', rep: :old_url],
].each do |args|
compile(*args) do
filter :erubis
filter :kramdown, input: 'GFM', header_offset: item[:kind] ? 1 : 0, enable_coderay: false, hard_wrap: false, auto_id_stripping: true, parse_block_html: true if item[:extension] == 'md'
filter :colorize_syntax, default_colorizer: :pygmentsrb
layout item[:kind] if item[:kind]
layout 'default'
end
end
route '/static/*' do
# Trim the leading /static and the trailing /
item.identifier[7..-2]
end
route '/posts/*/' do
item.identifier[6..-1] + 'index.html'
end
route '/404/' do
'/404.html'
end
route '/atom/' do
'/atom.xml'
end
route '/sitemap/' do
'/sitemap.xml'
end
route '*' do
item.identifier + 'index.html'
end
route '/posts/*/', rep: :old_url do
"/#{item[:date].year}/#{'%02d' % item[:date].month}#{item.identifier[6..-1]}index.html"
end
route '/contact/', rep: :old_url do
'/contact.html'
end
layout '*', :erubis