-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.rb
89 lines (69 loc) · 2.88 KB
/
script.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
@site.templates.find_all { |name, template| File.extname(template.path) == '.erb' }.each do |name, template|
template.use_filter :erb
end
@site.items.find_all { |item| File.extname(item.origin) == '.erb' && is_include?(item) }.each do |item|
item.destination.sub! /\.erb$/, '.html'
item.apply_filter :erb
item.apply_filter :reduce_empty_lines
end
all_posts.each do |item|
begin
item.destination = post_url(item) + 'index.html'
item.apply_filter :erb
item.apply_filter :kramdown
# Remove invalid markup from any footnotes.
item.content.gsub! %r{(<a href="#fn[^>]+) rel="(footnote|reference)"(>)}, '\1\3'
# Renumber any footnote link IDs so they can play nice if multiple posts are
# on a page, e.g. `/index.html`.
item.content.gsub! %r{(id="fn|href="#fn)(ref)?(:\d+")}, '\1\2-' + item.metadata[:published].to_i.to_s + '\3'
item.apply_template :post
# Restore any footnote link IDs because this is a single post page.
item.content.gsub! %r{(id="fn|href="#fn)(ref)?-\d+(:\d+")}, '\1\2\3'
# Adjust image links pointing to the post to point to the image instead.
item.content.gsub! %r{(<a href=")#{post_url(item)}("><img class="[^"]+" src=")([^"]+)}, '\1\3\2\3'
item.apply_filter :remove_more_marker
item.apply_filter :relative_to_absolute_urls
item.apply_filter :reduce_empty_lines
rescue StandardError => e
puts("Rescuing: #{e.message}, backtrace:\n#{e.backtrace}")
end
end
all_pages.each do |item|
item.destination = page_url(item) + 'index.html' unless item.destination != item.origin
item.apply_filter :erb
item.apply_filter :kramdown
if item.metadata.has_key? :template
item.apply_template item.metadata[:template]
else
item.apply_template :page
end
item.apply_filter :relative_to_absolute_urls
item.apply_filter :reduce_empty_lines
end
@site.items.find_all { |item| File.extname(item.origin) == '.erb' && !is_include?(item) }.each do |item|
item.destination.sub! /\.erb$/, ''
item.apply_filter :erb
item.apply_template item.metadata[:template] if item.metadata.has_key? :template
if item.destination =~ %r{\.html$}
item.apply_filter :relative_to_absolute_urls
elsif item.destination == '/rss.xml'
item.apply_filter :remove_more_marker
item.apply_filter :relative_to_absolute_urls
item.apply_filter :symbolic_to_numeric_entities
end
item.apply_filter :reduce_empty_lines
end
@site.items.find_all { |item| File.extname(item.origin) == '.sass' }.each do |item|
item.destination.sub! /sass$/, 'css'
item.apply_filter :sass, :style => :compact
item.content.gsub! /\n+/, "\n"
end
@site.items.find_all { |item| File.extname(item.origin) == '.coffee' }.each do |item|
item.destination.sub! /coffee$/, 'js'
item.apply_filter :coffeescript
item.content.lstrip!
item.content.gsub!(/(?:^|\G) {2}/m, "\t")
end
@site.items.find_all { |item| is_include?(item) }.each do |item|
item.abandon
end