-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig.rb
112 lines (99 loc) · 2.98 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
require 'builder'
# Activate and configure extensions
# https://middlemanapp.com/advanced/configuration/#configuring-extensions
# activate :autoprefixer do |prefix|
# prefix.browsers = "last 2 versions"
# end
set :markdown_engine, :redcarpet
set :markdown, :fenced_code_blocks => true, :smartypants => true, :tables => true, :footnotes => true
activate :directory_indexes
activate :syntax
page "/sitemap.xml", :layout => false
# Layouts
# https://middlemanapp.com/basics/layouts/
# Per-page layout changes
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
# With alternative layout
# page '/path/to/file.html', layout: 'other_layout'
# Proxy pages
# https://middlemanapp.com/advanced/dynamic-pages/
# proxy(
# '/this-page-has-no-template.html',
# '/template-file.html',
# locals: {
# which_fake_page: 'Rendering a fake page with a local variable'
# },
# )
# Build-specific configuration
# https://middlemanapp.com/advanced/configuration/#environment-specific-settings
configure :build do
activate :minify_css
activate :minify_javascript
end
chapters = {
"I": "Notions de base",
"II": "Conditions et pattern-matching",
"III": "Modéliser des données",
"IV": "Récursivité",
"V": "Coder, et bien coder",
"VI": "Polymorphisme",
"VII": "Ordre supérieur",
"VIII": "Le type list d’OCaml",
"IX": "Les arbres",
"X": "Annexes",
}
# Generate "prev" and "next" links for each page
ready do
chaps = [ "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X" ]
pages = {}
for r in sitemap.resources do
c = r.destination_path.split("/")[0]
if chaps.include?(c)
if pages[c] == nil
pages[c] = []
end
pages[c].push(r)
pages[c] = pages[c].sort_by { |x| x.destination_path }
end
end
for i in 0..(chaps.size - 1) do
p = i - 1
n = i + 1
prev_chap = if p >= 0 then pages[chaps[p]] else nil end
next_chap = if n < chaps.size then pages[chaps[n]] else nil end
j = 0
# puts i
# puts chaps[i]
# puts pages
for p in pages[chaps[i]] do
prev_page = if j == 0
if prev_chap == nil
nil
else
prev_chap[-1]
end
else
pages[chaps[i]][j - 1]
end
next_page = if (j + 1) == pages[chaps[i]].size
if next_chap == nil
nil
else
next_chap[0]
end
else
pages[chaps[i]][j + 1]
end
p.data.prev = if prev_page != nil then prev_page.destination_path.delete_suffix("/index.html") else nil end
p.data.next = if next_page != nil then next_page.destination_path.delete_suffix("/index.html") else nil end
p.data.chapter = chaps[i]
j += 1
end
end
for p in sitemap.resources do
p.data.chapters = chapters
# puts p.data
end
end