2014-10-21 19:55:55 +02:00
|
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
|
|
|
|
|
|
|
# A few helpful tips about the Rules file:
|
|
|
|
|
|
#
|
|
|
|
|
|
# * The string given to #compile and #route are matching patterns for
|
|
|
|
|
|
# identifiers--not for paths. Therefore, you can’t match on extension.
|
|
|
|
|
|
#
|
|
|
|
|
|
# * The order of rules is important: for each item, only the first matching
|
|
|
|
|
|
# rule is applied.
|
|
|
|
|
|
#
|
|
|
|
|
|
# * Item identifiers start and end with a slash (e.g. “/about/” for the file
|
|
|
|
|
|
# “content/about.html”). To select all children, grandchildren, … of an
|
|
|
|
|
|
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
|
|
|
|
|
|
# because “*” matches zero or more characters.
|
|
|
|
|
|
|
2018-07-12 12:14:37 +02:00
|
|
|
|
passthrough '/assets/**'
|
2020-10-14 20:04:54 +02:00
|
|
|
|
passthrough '/_redirects'
|
|
|
|
|
|
passthrough '*/images/*'
|
2017-11-07 22:23:41 +01:00
|
|
|
|
|
2015-06-02 16:40:39 +02:00
|
|
|
|
# RSS Feed
|
|
|
|
|
|
compile '/blog/feed/' do
|
|
|
|
|
|
filter :erb
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
route '/blog/feed/' do
|
|
|
|
|
|
'/blog/feed.xml'
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2014-10-21 19:55:55 +02:00
|
|
|
|
compile '*' do
|
2020-06-09 17:09:32 +02:00
|
|
|
|
filter :erb if item[:extension] == 'html'
|
2015-04-22 15:50:09 +02:00
|
|
|
|
|
2017-11-08 10:59:13 +01:00
|
|
|
|
if item[:extension] == 'md'
|
2015-01-08 16:09:23 +00:00
|
|
|
|
filter :redcarpet, options: {filter_html: true, autolink: true, no_intraemphasis: true, fenced_code_blocks: true, gh_blockcode: true, tables: true}, renderer_options: {with_toc_data: true}
|
2017-10-10 18:36:14 +02:00
|
|
|
|
filter :normalize_links, item[:repo_docs] if item[:repo_docs]
|
2020-10-14 20:04:54 +02:00
|
|
|
|
filter :version_warning, item[:repo_docs] if item[:repo_docs]
|
2014-10-21 19:55:55 +02:00
|
|
|
|
filter :add_anchors
|
|
|
|
|
|
filter :bootstrappify
|
|
|
|
|
|
filter :admonition
|
|
|
|
|
|
filter :colorize_syntax, :default_colorizer => :pygmentsrb
|
2017-03-04 14:36:33 -04:00
|
|
|
|
filter :config_linker if item[:title] == 'Configuration'
|
2016-01-20 00:07:19 -05:00
|
|
|
|
filter :toc, style: item[:toc]
|
2015-04-22 15:50:09 +02:00
|
|
|
|
if item[:kind] == 'article'
|
|
|
|
|
|
layout 'blog'
|
|
|
|
|
|
else
|
2018-01-08 17:55:27 +00:00
|
|
|
|
# TODO(mr): separate layout selection from Markdown handling
|
|
|
|
|
|
layout item[:layout] || 'docs'
|
2015-04-22 15:50:09 +02:00
|
|
|
|
end
|
2014-10-21 19:55:55 +02:00
|
|
|
|
elsif item[:extension] == 'css'
|
|
|
|
|
|
# don’t filter stylesheets
|
|
|
|
|
|
elsif item.binary?
|
|
|
|
|
|
# don’t filter binary items
|
2015-05-18 15:30:19 +01:00
|
|
|
|
elsif item[:layout]
|
|
|
|
|
|
layout item[:layout]
|
2014-10-21 19:55:55 +02:00
|
|
|
|
else
|
|
|
|
|
|
layout 'default'
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2015-04-22 15:50:09 +02:00
|
|
|
|
route '/blog/' do
|
|
|
|
|
|
'/blog/index.html'
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Transform /blog/<YYYY>-<MM>-<DD>-<post title> to
|
|
|
|
|
|
# /blog/<YYYY>/<MM>/<DD>/<post title>.
|
|
|
|
|
|
route '/blog/*' do
|
|
|
|
|
|
y, m, d, slug = /([0-9]+)\-([0-9]+)\-([0-9]+)\-([^\/]+)/.match(item.identifier).captures
|
|
|
|
|
|
|
|
|
|
|
|
"/blog/#{y}/#{m}/#{d}/#{slug}/index.html"
|
|
|
|
|
|
end
|
|
|
|
|
|
|
2014-10-21 19:55:55 +02:00
|
|
|
|
route '*' do
|
|
|
|
|
|
if item[:extension] == 'css'
|
|
|
|
|
|
# Write item with identifier /foo/ to /foo.css
|
2018-07-12 12:14:37 +02:00
|
|
|
|
item.identifier.chop + '.css'
|
2014-10-21 19:55:55 +02:00
|
|
|
|
elsif item.binary?
|
2018-07-12 12:14:37 +02:00
|
|
|
|
# Write item with identifier /foo.dat to /foo.dat
|
|
|
|
|
|
item.identifier.to_s
|
2014-10-21 19:55:55 +02:00
|
|
|
|
else
|
|
|
|
|
|
# Write item with identifier /foo/ to /foo/index.html
|
|
|
|
|
|
item.identifier + 'index.html'
|
|
|
|
|
|
end
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
layout '*', :erb
|