3 # Copyright © 2018-2020 Nick Bowler
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 system("git", "submodule", "update", "--init")
21 # Remove dead annex keys from processing
22 @items.delete_if do |item|
23 l = File.readlink(item.raw_filename)
24 true if !File.exists?(item.raw_filename) and l =~ %r{/annex/objects/}
29 Open3.popen2("git", "rev-parse", "HEAD") do |stdin, stdout, result|
33 commit = val.chomp if result.value.success?
38 item[:gitrev] = commit if item_source(item)
42 @items.find_all('/weblog/*.md').each do |item|
43 item[:kind] ||= 'article'
48 item[:published] || File.stat(item.raw_filename).mtime
50 item[:updated] || File.stat(item.raw_filename).mtime
54 @items.find_all('/archive/**/*').each do |item|
55 dir = File.dirname(item.identifier)
57 archivedirs[dir] = true
58 dir = File.dirname(dir)
62 archivedirs.keys.sort_by{ |s| -s.length }.each do |dir|
64 pattern: "#{dir}/*{,/index.lst}",
65 title: "Index of #{dir}",
69 @items.create("", attrs, "#{dir}/index.lst")
74 # Gzip all text items for nginx http_static
75 if !ENV['GZIP_SITE'].to_s.empty?
76 reps = @items.flat_map(&:reps).each do |rep|
78 next if !file or rep.binary?
80 if system("gzip", "-ck9", file, [:out]=>[file + ".gz.tmp", "wb"])
81 system("touch", "-r", file, file + ".gz.tmp")
82 File.rename(file + ".gz.tmp", file + ".gz")
84 File.unlink(file + ".gz.tmp")
89 # Register URLs for git-annex keys
90 unless (uribase = ENV['ANNEX_URI_BASE'].to_s.chomp("/")).empty?
91 Open3.popen2("git", "-c", "core.bare=false", "annex", "registerurl") do
92 |stdin, stdout, result|
94 next if item.raw_filename.nil?
96 l = File.readlink(item.raw_filename)
97 next unless l =~ %r{/annex/objects/}
99 key = File.basename(l)
101 # Find output reps corresponding to this key, if any
102 item.reps.each do |rep|
103 next if rep.raw_path.nil?
105 FileUtils.identical?(item.raw_filename, rep.raw_path)
108 STDOUT.write(stdout.read_nonblock(100))
109 rescue EOFError, IO::WaitReadable
113 stdin.printf("%s %s%s\n", key, uribase, rep.path)
120 STDOUT.write(stdout.readpartial(100))
125 unless (rc = result.value).success?
126 printf("git annex registerurl failed: %s\n", rc.to_s)
132 compile '/**/index.lst' do
133 layout '/listing.erb'
134 layout '/default.xml'
135 layout '/default.xsl'
136 layout '/embed-svg.xsl'
137 filter :relativize_paths, type: :xml
138 filter :xhtml_compat, fix_doctype: true
139 write item.identifier.without_ext + ".xhtml"
142 compile '/license/gpl*.md' do
143 filter :kramdown, auto_ids: false, header_offset: -1
144 layout '/default.xml'
146 layout '/default.xsl'
147 filter :relativize_paths, type: :xml
152 compile '/**/*.md' do
154 filter :kramdown, auto_ids: false, header_offset: 1
156 layout '/default.xml'
157 layout '/default.xsl'
158 filter :relativize_paths, type: :xml
163 compile '/license/cc*.sgml' do
165 layout '/creativecommons.xsl'
166 layout '/default.xml'
167 layout '/default.xsl', "section-links": "yes"
168 filter :relativize_paths, type: :xml
173 compile '/license/cc*.xhtml' do
174 layout '/creativecommons.xsl'
175 layout '/default.xml'
176 layout '/default.xsl', "section-links": "yes"
177 filter :relativize_paths, type: :xml
182 compile '/images/*.jpg', rep: :large do
183 w, h = FastImage.size(item.raw_filename)
184 filename = item.identifier.without_ext + '-t1200.' + item.identifier.ext
185 filter :imgresize, width: [w, 1200].min, height: [h, 1200].min, cache: filename
189 compile '/images/*.jpg', rep: :medium do
190 w, h = FastImage.size(item.raw_filename)
191 filename = item.identifier.without_ext + '-t800.' + item.identifier.ext
192 if w > 900 or h > 900
193 filter :imgresize, width: 800, height: 800, cache: filename
198 compile '/images/*.jpg', rep: :info do
200 layout '/imginfo.xsl'
201 layout '/default.xml'
202 layout '/default.xsl'
203 filter :relativize_paths, type: :xml
208 compile '/**/*.scss' do
209 filter :sass, syntax: :scss
210 filter :css_source, uribase: \
211 "https://git.draconx.ca/gitweb/homepage.git/blob/" +
213 filter :css_clean_selectors, \
214 preserve_comments: true, \
216 write @item.identifier.without_ext + '.css'
219 compile '/**/*.svg' do
220 filter :scour, comment_stripping: true
221 write @item.identifier.to_s
224 compile '/icons/**/*.svg', rep: :icon32 do
225 filter :svg2png, width: 32, height: 32
226 write @item.identifier.without_ext + "-32.png"
230 filter :copybin if @item.binary?
231 write @item.identifier.to_s
234 layout '/**/*.xsl', :xsl