forked from oVirt/ovirt-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.rb
431 lines (342 loc) · 11 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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
###
# Site settings
###
# Look in data/site.yml for general site configuration
Time.zone = data.site.timezone || 'UTC'
# Automatic image dimensions on image_tag helper
activate :automatic_image_sizes
# Syntax highlighting
activate :syntax
# Make URLs relative
set :relative_links, true
# Set HAML to render HTML5 by default (when unspecified)
# It's important HAML outputs "ugly" HTML to not mess with code blocks
set :haml, format: :html5, ugly: true
# Set Markdown features for Kramdown
# (So our version of Markdown resembles GitHub's w/ other nice stuff)
set :markdown,
transliterated_header_ids: true,
parse_block_html: true,
parse_span_html: true,
tables: true,
hard_wrap: false,
input: 'GFM' # add in some GitHub-flavor (``` for fenced code blocks)
set :markdown_engine, :kramdown
set :asciidoc_attributes, %w(source-highlighter=coderay imagesdir=images)
set :asciidoctor,
toc: true,
numbered: true
# Set directories
set :css_dir, 'stylesheets'
set :fonts_dir, 'stylesheets/fonts'
set :js_dir, 'javascripts'
set :images_dir, 'images'
set :partials_dir, 'layouts'
###
# Blog settings
###
activate :blog do |blog|
blog.prefix = 'blog/'
blog.layout = 'post'
blog.tag_template = 'tag.html'
blog.calendar_template = 'calendar.html'
blog.default_extension = '.md'
blog.sources = ':year-:month-:day-:title.html'
# blog.permalink = ":year/:month/:day/:title.html"
blog.permalink = ':year/:month/:title.html'
blog.year_link = ':year.html'
blog.month_link = ':year/:month.html'
# blog.day_link = ":year/:month/:day.html"
blog.taglink = 'tag/:tag.html'
# blog.summary_separator = /(READMORE)/
# blog.summary_length = 99999
blog.paginate = true
blog.per_page = 10
blog.page_link = 'page=:num'
end
# activate :authors
# activate :drafts
# Enable blog layout for all blog pages
with_layout :post do
page '/blog.html'
page '/blog/*'
end
# Make pretty URLs
activate :directory_indexes
###
# Compass
###
# Change Compass configuration
# compass_config do |config|
# config.output_style = :compact
# end
###
# Page options, layouts, aliases and proxies
###
# Per-page layout changes:
#
# With no layout
# page "/path/to/file.html", :layout => false
#
# With alternative layout
# page "/path/to/file.html", :layout => :otherlayout
#
# A path which all have the same layout
# with_layout :admin do
# page "/admin/*"
# end
# Don't have a layout for XML
page '*.xml', layout: false
# Docs all have the docs layout
with_layout :docs do
# page "/documentation/*"
# page "/documentation*"
end
with_layout :feature do
page "/develop/release-management/features/*"
end
# Don't make these URLs have pretty URLs
page '/404.html', directory_index: false
page '/.htacces.html', directory_index: false
# Proxy pages (http://middlemanapp.com/dynamic-pages/)
# proxy "/this-page-has-no-template.html", "/template-file.html", :locals => {
# :which_fake_page => "Rendering a fake page with a local variable" }
proxy '/.htaccess', '/.htaccess.html', locals: {}, ignore: true
ready do
# Add yearly calendar pages
data.events.each do |year, data|
next unless year.match(/[0-9]{4}/)
proxy "/events/#{year}.html", "events/index.html", locals: {year: year}
end
# Add author pages
sitemap.resources.group_by { |p| p.data['author'] }.each do |author, pages|
next unless author
proxy "/blog/author/#{author.parameterize.downcase}.html",
'author.html',
locals: { author: author, pages: pages },
ignore: true
end
proxy '/blog/author.html', 'author.html', ignore: true
# Add blog feeds
blog.tags.each do |tag_name, _tag_data|
next unless tag_name
proxy "/blog/tag/#{tag_name.downcase}.xml",
'feed.xml',
locals: { tag_name: tag_name },
ignore: true
end
proxy '/blog/feed.xml', 'feed.xml', ignore: true
proxy '/blog/tag/index.html', 'tag.html', ignore: true
sitemap.resources.reject { |p| p.data.wiki_title.nil? }.each do |p|
next unless p.data.wiki_title.match(/^category:/i)
page p.path, layout: 'category'
end
# Auto-add index.html.md pages where they are lacking
Dir.glob('source/**/').each do |path|
next if Dir.glob("#{path}index.*").count > 0
next if /source\/(images|stylesheets|javascripts|fonts|blog)/.match path
path_url = path.sub('source', '')
proxy "#{path_url}index.html",
'indexless.html',
locals: { path: path_url },
ignore: true
end
end
###
# Helpers
###
# Methods defined in the helpers block are available in templates
# helpers do
# def some_helper
# "Helping"
# end
# end
# helpers do
# end
require 'lib/site_helpers.rb'
activate :site_helpers
require 'lib/blog_helpers.rb'
activate :blog_helpers
require 'lib/confcal.rb'
activate :confcal
require 'lib/monkeypatch_blog_date.rb'
###
# Monkey patches
###
helpers do
alias_method :_link_to, :link_to
alias_method :_image_tag, :image_tag
# Monkey patch Middleman's image_tag to add missing image support
# (and look for space-to-underscore conversions like MediaWiki)
def image_tag(path, params = {})
unless path.include?('://')
real_path = path
real_path = File.join(images_dir, real_path) unless real_path.start_with?('/')
full_path = File.join(source_dir, real_path)
filename = File.basename(path)
# Try harder. (Look all over the resources)
unless File.exist?(full_path)
match = sitemap.resources.select do |resource|
p = resource.path
result = p.match(/#{filename}|#{filename.gsub(/ /, '_')}$/i)
# Try even harder. (Look for similar filenames; handles conversions)
unless result
noext = filename.chomp(File.extname(filename))
exts = 'png|gif|jpg|jpeg|svg'
result = p.match(/(#{noext}|#{noext.gsub(/ /, '_')})\.(#{exts})$/i)
end
result
end.first
# resource's `url` is user-specified; `path` is a full path
path = match.url if match
end
end
_image_tag(path, params)
end
# WIP!!!
# Monkeypatch Middleman's link_to to add missing page support
# (and search MediaWiki imported files)
def link_to(*args, &block)
begin
url_index = block_given? ? 0 : 1
url = args[url_index]
current_file = current_page.source_file.gsub("#{root}/#{source}/", '')
# Strip site referential links
if args[url_index].respond_to?('gsub!')
args[url_index].gsub!(/https?:\/\/(www.)?ovirt.org\//, '')
end
if url.respond_to?('gsub') && url.respond_to?('match') && !url.match(/^http|^#/)
p args if url.match(/Special:/)
if url.match(/^(Special:|User:)/i)
# puts "WARNING: #{current_file}: Invalid link to '#{args[1]}'"
return "<span class='broken-link link-mediawiki' data-href='#{url}' title='Special MediaWiki link: original pointed to: #{url}'>#{args.first}</span>"
end
url_extra = ''
match = sitemap.resources.select do |resource|
extra = /[#\?].*/
url_extra = url.match(extra)
url_fixed = url.gsub(/_/, ' ').gsub(extra, '')
resource.data.wiki_title.to_s.downcase.strip == url_fixed.gsub(/_/, ' ').downcase.strip
end.sort_by { |r| File.stat(r.source_file).size }.reverse.first
args[url_index] = match.url + url_extra.to_s if match
end
result = _link_to(*args, &block)
rescue
puts "ERROR: #{current_file}: Issue with link to '#{args[1]}'"
return "<span class='broken-link link-error' data-href='#{url}' title='Broken link: original pointed to: #{url}'>#{args.first}</span>"
end
result
end
end
###
# Development-only configuration
###
#
configure :development do
puts "\nUpdating git submodules..."
puts `git submodule init && git submodule sync`
puts `git submodule foreach "git pull -qf origin master"`
puts "\n"
puts '== Administration is at http://0.0.0.0:4567/admin/'
activate :livereload
# config.sass_options = {:debug_info => true}
# config.sass_options = {:line_comments => true}
compass_config do |config|
config.output_style = :expanded
config.sass_options = { debug_info: true, line_comments: true }
end
end
# Build-specific configuration
configure :build do
puts "\nUpdating git submodules..."
puts `git submodule init`
puts `git submodule foreach "git pull -qf origin master"`
puts "\n"
## Ignore administration UI
ignore '/admin/*'
ignore '/javascripts/admin*'
ignore '/stylesheets/lib/admin*'
## Ignore Gimp source files
ignore 'images/*.xcf*'
# Don't export source JS
ignore 'javascripts/vendor/*'
ignore 'javascripts/lib/*'
# Don't export source CSS
ignore 'stylesheets/vendor/*'
ignore 'stylesheets/lib/*'
ignore 'events-yaml*'
# Minify JavaScript and CSS on build
activate :minify_javascript
activate :minify_css
# activate :gzip
# Force a browser reload for new content by using
# asset_hash or cache buster (but not both)
activate :cache_buster
# activate :asset_hash
# Use relative URLs for all assets
# activate :relative_assets
# Compress PNGs after build
# First: gem install middleman-smusher
# require "middleman-smusher"
# activate :smusher
# Or use a different image path
# set :http_path, "/Content/images/"
# Favicon PNG should be 144×144 and in source/images/favicon_base.png
# Note: You need ImageMagick installed for favicon_maker to work
activate :favicon_maker do |f|
f.template_dir = File.join(root, 'source', 'images')
f.output_dir = File.join(root, 'build', 'images')
f.icons = {
'favicon_base.png' => [
{ icon: 'favicon.png', size: '16x16' },
{ icon: 'favicon.ico', size: '64x64,32x32,24x24,16x16' }
]
}
end
end
###
# Deployment
##
if data.site.openshift
os_token, os_host = data.site.openshift.match(/([0-9a-f]+)@([^\/]+)/).captures
deploy_config = {
method: :rsync,
user: os_token,
host: os_host,
path: "/var/lib/openshift/#{os_token}/app-root/repo",
clean: true, # remove orphaned files on remote host
build_before: false # default false
}
elsif data.site.rsync
rsync = URI.parse(data.site.rsync)
deploy_config = {
method: :rsync,
user: rsync.user || ENV[:USER],
host: rsync.host,
path: rsync.path,
port: rsync.port || 22,
clean: true, # remove orphaned files on remote host
build_before: true # default false
}
else
# For OpenShift,
#
# 1) use the barebones httpd cartridge from:
# http://cartreflect-claytondev.rhcloud.com/reflect?github=stefanozanella/openshift-cartridge-httpd
# (Add as URL at the bottom of the create from cartridge page)
#
# 2) Copy your new site's git repo URL and use it for 'production':
# git remote add production OPENSHIFT_GIT_REMOTE_HERE
#
# 3) Now, you can easily deploy to your new OpenShift site!
# bundle exec middleman deploy
deploy_config = {
method: :git,
remote: 'production',
branch: 'master',
build_before: true # default false
}
end
activate :deploy do |deploy|
deploy_config.each { |key, val| deploy[key] = val }
end