-
Notifications
You must be signed in to change notification settings - Fork 108
/
config.rb
242 lines (194 loc) · 6.53 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# frozen_string_literal: true
require 'pathname'
$LOAD_PATH.unshift(Pathname('./lib').realpath)
require 'rom/site'
# Per-page layout changes:
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
page '/', layout: 'layout'
page '/learn/*', layout: 'guide', data: { sidebar: 'learn/sidebar' }
page '/guides/*', layout: 'guide', data: { sidebar: 'guides/sidebar' }
page '/blog/*', data: { sidebar: 'blog/sidebar' }
# Pre-docsite docs with global versions
page '/3.0/learn/*', layout: 'guide', data: { sidebar: '3.0/learn/sidebar' }
page '/3.0/guides/*', layout: 'guide', data: { sidebar: '3.0/guides/sidebar' }
page '/4.0/learn/*', layout: 'guide', data: { sidebar: '4.0/learn/sidebar' }
page '/4.0/guides/*', layout: 'guide', data: { sidebar: '4.0/guides/sidebar' }
page '/5.0/learn/*', layout: 'guide', data: { sidebar: '5.0/learn/sidebar' }
page '/5.0/guides/*', layout: 'guide', data: { sidebar: '5.0/guides/sidebar' }
Middleman::Docsite.projects.each do |project|
proxy "/api/#{project.name}/index.html", '/api/project.html', layout: 'api', locals: { project: project }, ignore: true
end
Middleman::Docsite.projects.select(&:versioned?).each do |project|
proxy(
"/learn/#{project.slug}/index.html",
'/project-index-redirect.html',
locals: { path: project.latest_path },
layout: false,
ignore: true
)
end
set :api_base_url, 'https://api.rom-rb.org'
set :api_url_template, "#{config.api_base_url}/%{project}/ROM/%{path}"
set :api_anchor_url_template, "#{config.api_base_url}/%{project}/ROM/%{path}#%{anchor}"
# Helpers
helpers do
def projects
docsite.projects
end
def docsite_projects
projects.select(&:versioned?)
end
def docsite
Middleman::Docsite
end
def nav_link_to(link_text, url, options = {})
root = options.delete(:root)
is_active = (!root && current_page.url.start_with?(url)) ||
current_page.url == url
options[:class] ||= ''
options[:class] << '--is-active' if is_active
link_to(link_text, url, options)
end
def learn_root_resources
resources =
non_project_learn_resources
.map { |r| [r, r.data.position] } +
project_learn_resources
.map.with_index { |r, i| [r, i + 1] }
resources.sort_by(&:last).map(&:first)
end
def project_learn_resources
docsite_projects
.map { |project|
sitemap
.find_resource_by_destination_path(
"learn/#{project.slug}/#{project.latest_version}/index.html"
)
}
end
def non_project_learn_resources
Dir[docsite.source_dir.join("*")]
.map(&method(:Pathname))
.reject(&:file?)
.reject { |path| projects.map(&:slug).include?(path.basename.to_s) }
.map { |path|
sitemap
.find_resource_by_destination_path("learn/#{path.basename}/index.html")
}
end
def legacy_learn_root_resource
sitemap.find_resource_by_destination_path("#{version}/learn/index.html")
end
def legacy_guides_root_resource
sitemap.find_resource_by_destination_path("#{version}/guides/index.html")
end
def guides_root_resource
sitemap.find_resource_by_destination_path("guides/index.html")
end
def sections_as_resources(resource)
sections = resource.data.sections
sections.map do |section|
destination_path = resource.url + "#{section}/index.html"
sitemap.find_resource_by_destination_path(destination_path)
end
end
def head_title
current_page.data.title.nil? ? 'ROM' : "ROM - #{current_page.data.title}"
end
def guide_title
[current_page.data.chapter, current_page.data.title].compact.join(' » ')
end
def og_url
Middleman::Docsite.development? ? current_page.url : "http://rom-rb.org#{current_page.url}"
end
def og_description
if current_page.data.description.nil?
'An open-source persistence and mapping toolkit for Ruby built for speed and simplicity.'
else
current_page.data.description
end
end
def og_image
'http://rom-rb.org/images/logo--card.png'
end
def copyright
"© 2014-#{Time.now.year} Ruby Object Mapper."
end
def design_by
url = 'https://github.com/angeloashmore'
"Design by #{link_to '@angeloashmore', url}."
end
def logo_by
url = 'https://github.com/kapowaz'
"Logo by #{link_to '@kapowaz', url}."
end
def version
current_path[%r{(\d+\.\d+)}] || 'main'
end
def versions_match?(v1, v2)
v1 == v2
end
def version_variants
["3.0", "4.0", "5.0"]
end
GH_NEW_ISSUE_URL = 'https://github.com/rom-rb/rom-rb.org/issues/new?labels=%{labels}&assignees=%{assignees}&title=%{title}'
def feedback_link
tokens = {
title: "Feedback on #{URI.encode(head_title)}",
labels: 'feedback',
assignees: 'solnic'
}
link_to 'Provide feedback!', GH_NEW_ISSUE_URL % tokens, class: 'button'
end
def current_branch
@current_branch ||= `git branch`.chomp.split("\n").map(&:strip).grep(/^\*/)[0].split.last
end
GH_EDIT_FILE_URL = 'https://github.com/rom-rb/rom-rb.org/blob/%{branch}%{current_path}'
def edit_file_link
match = current_source_file[%r[(\w+)/(\d+\.\d+)]]
project_slug, version = match ? match.split('/') : []
url =
if project_slug != "source" && version
project = docsite_projects.detect { |p| p.slug.eql?(project_slug) }
project.file_url(version, current_source_file)
else
GH_EDIT_FILE_URL % { branch: current_branch, current_path: current_source_file }
end
link_to 'Edit on GitHub', url, class: 'button'
end
def current_source_file
current_page.source_file.gsub(Dir.pwd, '')
end
end
# General configuration
set :build_dir, 'docs'
set :layout, 'content'
set :css_dir, 'assets/stylesheets'
set :js_dir, 'assets/javascripts'
set :markdown_engine, :redcarpet
set :markdown, renderer: ROM::Site::Markdown::Renderer,
tables: true,
autolink: true,
gh_blockcode: true,
fenced_code_blocks: true,
with_toc_data: true
set :disqus_embed_url, 'https://rom-rb-blog.disqus.com/embed.js'
activate :blog,
prefix: 'blog',
layout: 'blog_article',
permalink: '{title}.html',
paginate: true,
tag_template: 'blog/tag.html'
activate :syntax, css_class: 'syntax'
activate :directory_indexes
activate :external_pipeline,
name: :webpack,
command: build? ? 'node ./node_modules/webpack/bin/webpack.js --bail' : 'node ./node_modules/webpack/bin/webpack.js --watch -d',
source: 'tmp/dist',
latency: 1
begin
require 'pry-byebug'
rescue LoadError
end