-
Notifications
You must be signed in to change notification settings - Fork 10
/
soupault.toml
190 lines (144 loc) · 5.03 KB
/
soupault.toml
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
### Configuration file for the soupault website generator ###
## Global settings
[settings]
# Require soupault 4.0.0 or later
soupault_version = "4.0.0"
# Fail on page processing errors
strict = true
verbose = true
debug = false
# Where generated files go
build_dir = "build"
# Where page files are stored
site_dir = "book/"
# Where in the template the page content is inserted
default_content_selector = "main"
# There's a div for footnotes inside <main>,
# so we want to insert the content before it
default_content_action = "prepend_child"
default_template_file = "templates/main.html"
# Page considered the section index
index_page = "index"
page_file_extensions = ["html", "md"]
doctype = "<!DOCTYPE html>"
## Preprocessors
[preprocessors]
# Run *.md files through cmark to convert them to HTML
# before further processing
md = "cmark --unsafe --smart"
# This hook removes chapter numbers from output file names,
# so that book/00_preface.md becomes /preface
[hooks.pre-process]
lua_source = '''
target_file_name = Sys.basename(target_file)
target_page_dir = Sys.basename(target_dir)
target_page_parent_dir = Sys.dirname(target_dir)
target_page_dir = Regex.replace(target_page_dir, "^\\d+_", "")
target_dir = Sys.join_path(target_page_parent_dir, target_page_dir)
target_file = Sys.join_path(target_dir, target_file_name)
Log.debug(format("Target file name set to \"%s\"", target_file))
'''
# This hook extracts chapter numbers from source file names
# and adds them to page metadata
[hooks.post-index]
lua_source = '''
Log.debug("Extracting chapter number")
page_file_name = Sys.basename(page_file)
res = Regex.find_all(page_file_name, "^(\\d+)")
if res then
chapter_number = res[1]
else
chapter_number = 0
end
index_fields["chapter_number"] = format("%s", chapter_number)
Log.debug(JSON.pretty_print(index_fields))
'''
[index]
index = true
# Make the index data available even to content pages,
# at cost of making a reduced first pass to extract that data
# before the "real" build
#
# This is to allow every page to generate a sidebar with all chapters
index_first = true
sort_by = "chapter_number"
sort_type = "numeric"
sort_descending = false
[index.fields]
title = { selector = ["#title", "h1"] }
## Widgets
# Takes the content of the first <h1> and inserts it into the <title>
[widgets.page-title]
widget = "title"
selector = "h1"
default = "OCaml From the Ground Up"
append = " — OCaml From the Ground Up"
# Moves all elements with class="footnote" to <div id="footnotes">
# and replaces them with numbered links.
[widgets.footnotes]
widget = "footnotes"
selector = "div#footnotes"
footnote_selector = ".footnote"
footnote_link_class = "footnote"
# From plugins/footnotes-cleanup.lua
# Removes the <div> meant for footnotes if there are no footnotes in the chapter
[widgets.footnotes-container-cleanup]
widget = "footnotes-cleanup"
after = "footnotes"
footnote_link_selector = "a.footnote"
footnotes_container_selector = "div#footnotes"
[widgets.table-of-contents]
exclude_page = "index.md"
widget = "toc"
selector = "h1"
action = "insert_after"
min_level = 2
toc_list_class = "toc"
toc_class_levels = false
numbered_list = true
heading_links = true
heading_link_text = "→ "
heading_link_class = "here"
use_heading_slug = true
[widgets.cleanup-table-of-contents]
widget = "delete_element"
after = "table-of-contents"
selector = "div#toc"
only_if_empty = true
[widgets.insert-chapters-index]
widget = "chapters-index"
index_selector = "div#chapters-index"
index_template = '''
<ul class="toc">
<li> <a href="/">About this book</a> </li>
{% for e in entries %}
<li> <a href="{{e.url}}">{{e.title}}</a> </li>
{% endfor %}
</ul>
'''
# Runs OCaml code snippets through compiler's type-checking phase
# to make the build fail if a snippet is syntactically incorrect or ill-typed
[widgets.ocaml-compile]
widget = "preprocess_element"
selector = '.language-ocaml'
# Unfortunately, ocamlc doesn't support reading from stdin,
# so we have to create temporary files.
# This approach may be better to replace with a dedicated plugin
# that will also clean up temporary files immediately after use...
command = 'cat > /tmp/code_sample_$PPID.ml && ocamlc -stop-after typing /tmp/code_sample_$PPID.ml'
action = 'ignore_output'
# Runs the content of <* class="language-*"> elements through a syntax highlighter
[widgets.highlight-ocaml]
after = "ocaml-compile"
widget = "preprocess_element"
selector = ['.language-ocaml']
command = 'highlight -O html -f --syntax=ocaml'
action = "replace_content"
# Some snippets are intentionally invalid to demonstrate typical programming errors
# They should be exempt from compiler checks
[widgets.highlight-bad-ocaml]
after = "ocaml-compile"
widget = "preprocess_element"
selector = '.language-invalid-ocaml'
command = 'highlight -O html -f --syntax=ocaml'
action = "replace_content"