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
|
# File 'lib/jekyll-viewsource.rb', line 36
def generate(site)
ViewSource.site(site)
config = site.config[VIEWSOURCE] || {}
return unless config["enabled"].nil? || config["enabled"]
config['options'] ||= ''
@debug = config["debug"]
ViewSource.debug_state @debug
Cache.setup(site, config['cache'].nil? || config['cache'])
config['collection'] = config['collection'].split(/,\s*/) if config['collection'].is_a?(String)
collections = [ config['collection'], config["collections"] ].flatten.compact.uniq
collections = [ "posts", "pages" ] if collections.empty?
collections.each do |collection|
if collection == "pages"
items = site.pages
else
next if !site.collections.has_key?(collection)
items = site.collections[collection].docs
end
process = items.select { |item| item.data[VIEWSOURCE]}
process.each do |item|
vs_opts = item.data[VIEWSOURCE].to_s + ' ' + config['options']
if m = /pretty\s*=?\s*(['"](.*?)['"]|)/.match(vs_opts)
pretty = m[2] || DEFAULT_CSS
end
if m = /linkback\s*=?\s*(['"](.*?)['"]|)/.match(vs_opts)
linkback = m[2] || 'Back'
end
view_md = (vs_opts =~ /\b(md|markdown)\b/i)
view_pr = (vs_opts =~ /\b(prerender)\b/i)
view_html = (vs_opts =~ /\bhtml\b/i)
view_md ||= !view_html
suffix = (pretty ? INFIXED_HTML : INFIXED_TXT)
if view_md || view_pr
dest_folder = Pathname(item.url).dirname
dest_folder = '' if dest_folder.to_s == '/'
filename = File.basename(item.path)
item.data[MD_FILE_PROP] = "#{dest_folder}/#{filename}"
if view_md
item.data[MD_SOURCE_URL] = item.data[MD_FILE_PROP] + suffix
end
if view_pr
item.data[PR_SOURCE_URL] = item.data[MD_FILE_PROP] + suffix
end
end
if view_html
item.data[HTML_FILE_PROP] = "#{item.destination('')}".sub!(site.dest, '')
item.data[HTML_SOURCE_URL] = item.data[HTML_FILE_PROP] + suffix
end
item.data[PRETTY_PROP] = pretty
item.data[LINKBACK_PROP] = "#{item.url}|$|#{linkback}" if linkback
if view_md || view_html
Renderer.enqueue(item)
elsif view_pr
Renderer.enqueue(item, PR)
end
end
end
end
|