This repository has been archived by the owner on Mar 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 155
/
config.rb
156 lines (119 loc) · 3.23 KB
/
config.rb
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
module CustomRenderers
class SemanticTOC < Redcarpet::Render::HTML_TOC
def preprocess text
@current_level = 0
@headers = []
text
end
def header text, level
id = text.downcase.strip.gsub(' ', '-').gsub(/\(.+\)/, '').gsub(/[^\w-]/, '')
if(@headers.include?(id))
while @headers.include?(id) do
if id[-1].to_i.zero?
id = id + "-1"
else
id[-1] = (id[-1].to_i + 1).to_s
end
if [email protected]?(id)
@headers.push(id)
break
end
end
else
@headers.push(id)
end
buf = ""
if level > 1 && level < 5
if (@current_level == 0)
@level_offset = level - 1;
end
level -= @level_offset
if (level > @current_level)
while (level > @current_level)
buf << "<ol><li>"
@current_level += 1
end
elsif (level < @current_level)
buf << "</li>"
while (level < @current_level)
buf << "</ol></li>"
@current_level -= 1
end
buf << "<li>"
else
buf << "</li><li>"
end
buf << "<a href='##{id}'>#{text}</a>"
end
buf
end
def postprocess text
"<div class='semantic-toc'>#{text}</div>\n\n"
end
end
class Markdown < Redcarpet::Render::HTML
TableOfContentsRenderer = ::Redcarpet::Markdown.new(CustomRenderers::SemanticTOC)
include Redcarpet::Render::SmartyPants
def preprocess text
@headers = []
toc = TableOfContentsRenderer.render text
text.gsub!("<!-- table_of_contents -->", toc)
return text
end
def header text, level
if level > 1 && level < 5
id = text.downcase.strip.gsub(' ', '-').gsub(/\(.+\)/, '').gsub(/[^\w-]/, '')
if(@headers.include?(id))
while @headers.include?(id) do
if id[-1].to_i.zero?
id = id + "-1"
else
id[-1] = (id[-1].to_i + 1).to_s
end
if [email protected]?(id)
@headers.push(id)
break
end
end
else
@headers.push(id)
end
"<h#{level}>
<a id='#{id}' class='section-link'></a>
<a href='##{id}' class='header-link'>Link</a>
#{text}
<a href='#' class='back-to-top-link'>Back to Top</a>
</h#{level}>"
else
"<h#{level}>#{text}</h#{level}>"
end
end
end
end
activate :directory_indexes
set :css_dir, 'assets/css'
set :js_dir, 'assets/javascripts'
set :images_dir, 'assets/images'
set :fonts_dir,'assets/fonts'
set :index_file, 'index.html'
set :markdown_engine, :redcarpet
set :source, 'docs'
set :build_dir, 'docs-build'
set :markdown,
:renderer => CustomRenderers::Markdown,
:fenced_code_blocks => true,
:tables => true,
:no_intra_emphasis => true,
:strikethrough => true,
:superscript => true,
:highlight => true,
:footnotes => true,
:autolink => true,
:with_toc_data => true
activate :rouge_syntax
# Build-specific configuration
configure :build do
activate :minify_css
activate :minify_javascript
activate :asset_hash
end