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
|
#!/usr/bin/env ruby
preprocess do
@items.each do |item|
if item.identifier.to_s.end_with?(".md") && !item.binary?
begin
# If the page is a redirect, make it a redirect.
if item.raw_content =~ /^This document was moved to \[.*\]\(.*\)/m
# Capture the intended page so the redirect page can redirect to it.
item[:redirect] = item.raw_content.match(/^This document was moved to \[.*\]\((.*)\)/m)[1]
# Correct the URL.
item[:redirect] = item[:redirect].gsub!(/\.md/, '.html')
end
title = item.raw_content.match(/^[#] .*$/).to_s
title.gsub!('# ', '')
item[:title] = title unless title.empty?
# Encoding errors happen on some files for some reason, so we
# rescue them.
rescue Encoding::CompatibilityError
puts "(warning) Encoding error: #{item.identifier}"
end
end
end
end
compile '/404.*' do
filter :erb
layout '/404.*'
write '/404.html'
end
compile '/**/*.html' do
layout '/default.*'
end
compile '/**/*.md' do
if item[:redirect].nil?
# Use Redcarpet with Rouge.
filter :redcarpet,
renderer: HTML,
options: {
fenced_code_blocks: true,
footnotes: true,
lax_spacing: true,
no_intra_emphasis: true,
space_after_headers: true,
strikethrough: true,
superscript: true,
tables: true,
autolink: true
},
renderer_options: {
with_toc_data: true
}
layout '/default.*'
filter :md_to_html_ext
filter :edit_on_gitlab_link
else
layout '/redirect.*'
end
end
compile '/**/*.scss' do
filter :sass,
syntax: :scss,
style: :compressed
write item.identifier.without_ext + '-v' + rep.item[:version].to_s + '.css'
end
compile '/index.*' do
filter :erb
layout '/home.*'
write '/index.html'
end
compile '/sitemap.*' do
filter :erb
write '/sitemap.xml'
end
compile '/robots.*' do
filter :erb
write '/robots.txt'
end
route '/**/*.{html,md}' do
if item.identifier =~ '/index.*'
'/index.html'
else
item.identifier.without_ext + '.html'
end
end
compile '/**/*' do
unless item.identifier.ext == 'scss'
write item.identifier.to_s
end
end
layout '/**/*', :erb
# Leave the favicon alone.
passthrough '/favicon.ico'
|