-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rb
166 lines (141 loc) · 3.49 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
157
158
159
160
161
162
163
164
165
166
require "lib/models/history"
require "helpers/url_helpers"
include UrlHelpers
# Activate and configure extensions
# https://middlemanapp.com/advanced/configuration/#configuring-extensions
config[:mode] = (ENV.fetch("MODE") { build? ? "build" : "server" }).to_sym
config[:path_prefix] = ENV.fetch("PATH_PREFIX") { "" }
activate :aria_current
activate :external_pipeline,
name: :webpack,
command: build? ? "yarn build" : "yarn start",
source: "tmp/dist",
latency: 1
activate :inline_svg do |config|
config.defaults = {
role: "img",
}
end
activate :syntax
set :markdown_engine, :redcarpet
set :markdown, fenced_code_blocks: true, smartypants: true, with_toc_data: true
# 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'
# },
# )
repository_directory = Pathname(ENV.fetch("GIT_DIR", File.dirname(__FILE__)))
repository = Git.open(repository_directory)
repository.tags.each do |tag|
stale_history = History.new(
name: repository_directory.basename,
readme: repository.show("#{tag.name}:README.md") ,
repository: repository,
root: tag,
out_of_date: true,
)
stale_history.commits.each do |commit|
proxy(
commit_path(commit),
"/commits/commit.html",
locals: {
history: stale_history,
commit: commit,
page: {
title: commit.subject,
},
render_diffs: true,
},
ignore: true,
)
end
proxy(
tag_path(tag),
"README.html",
locals: {
history: stale_history,
commit: stale_history.initial_commit,
contents: stale_history.readme,
page: {
title: stale_history.readme.lines.first,
},
render_diffs: false,
},
ignore: true,
)
end
history = History.new(
name: repository_directory.basename,
readme: repository.show("HEAD:README.md"),
repository: repository,
root: repository
)
history.commits.each do |commit|
proxy(
"/commits/#{commit.sha}/index.html",
"/commits/commit.html",
locals: {
history: history,
commit: commit,
page: {
title: commit.subject,
},
render_diffs: true,
},
ignore: true,
)
end
proxy(
"index.html",
"README.html",
locals: {
history: history,
commit: history.initial_commit,
contents: history.readme,
page: {
title: history.readme.lines.first,
},
render_diffs: false,
},
ignore: true,
)
# Helpers
# Methods defined in the helpers block are available in templates
# https://middlemanapp.com/basics/helper-methods/
# helpers do
# def some_helper
# 'Helping'
# end
# end
helpers do
def markdown(content)
template = Tilt[:md].new { content }
template.render
end
def adjacent_commits(history, commit:)
[nil].chain(history).chain([nil]).each_cons(3).detect do |_, middle, _|
commit.sha == middle.sha
end
end
end
# Build-specific configuration
# https://middlemanapp.com/advanced/configuration/#environment-specific-settings
# configure :build do
# activate :minify_css
# activate :minify_javascript
# end
configure :build do
activate :relative_assets
end