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 # Remove dead annex keys from processing
20 @items.delete_if do |item|
21 l = File.readlink(item.raw_filename)
22 true if !File.exists?(item.raw_filename) and l =~ %r{/annex/objects/}
27 Open3.popen2("git", "rev-parse", "HEAD") do |stdin, stdout, result|
31 commit = val.chomp if result.value.success?
36 item[:gitrev] = commit if item_source(item)
40 @items.find_all('/weblog/*.md').each do |item|
41 item[:kind] ||= 'article'
46 item[:published] || File.stat(item.raw_filename).mtime
48 item[:updated] || File.stat(item.raw_filename).mtime
53 # Gzip all text items for nginx http_static
54 if !ENV['GZIP_SITE'].to_s.empty?
55 reps = @items.flat_map(&:reps).each do |rep|
57 next if !file or rep.binary?
59 if system("gzip", "-ck9", file, [:out]=>[file + ".gz.tmp", "wb"])
60 system("touch", "-r", file, file + ".gz.tmp")
61 File.rename(file + ".gz.tmp", file + ".gz")
63 File.unlink(file + ".gz.tmp")
68 # Register URLs for git-annex keys
69 unless (uribase = ENV['ANNEX_URI_BASE'].to_s.chomp("/")).empty?
70 Open3.popen2("git", "annex", "registerurl") do |stdin, stdout, result|
72 l = File.readlink(item.raw_filename)
73 next unless l =~ %r{/annex/objects/}
75 key = File.basename(l)
77 # Find output reps corresponding to this key, if any
78 item.reps.each do |rep|
80 FileUtils.identical?(item.raw_filename, rep.raw_path)
83 STDOUT.write(stdout.read_nonblock(100))
84 rescue EOFError, IO::WaitReadable
88 stdin.printf("%s %s%s\n", key, uribase, rep.path)
95 STDOUT.write(stdout.readpartial(100))
100 unless (rc = result.value).success?
101 printf("git annex registerurl failed: %s\n", rc.to_s)
107 compile '/license/gpl*.md' do
108 filter :kramdown, auto_ids: false, header_offset: -1
109 layout '/default.xml'
111 layout '/default.xsl'
112 filter :relativize_paths, type: :xml
118 compile '/**/*.md' do
120 filter :kramdown, auto_ids: false, header_offset: 1
122 layout '/default.xml'
123 layout '/default.xsl'
124 filter :relativize_paths, type: :xml
130 compile '/license/cc*.sgml' do
132 layout '/creativecommons.xsl'
133 layout '/default.xml'
134 layout '/default.xsl', "section-links": "yes"
135 filter :relativize_paths, type: :xml
141 compile '/license/cc*.xhtml' do
142 layout '/creativecommons.xsl'
143 layout '/default.xml'
144 layout '/default.xsl', "section-links": "yes"
145 filter :relativize_paths, type: :xml
151 compile '/images/*.jpg', rep: :large do
152 filter :imgresize, width: 1200, height: 1200
153 write item.identifier.without_ext + '-t1200.' + item.identifier.ext
156 compile '/images/*.jpg', rep: :info do
158 layout '/imginfo.xsl'
159 layout '/default.xml'
160 layout '/default.xsl'
161 filter :relativize_paths, type: :xml
167 compile '/**/*.scss' do
168 filter :sass, syntax: :scss
169 filter :css_source, uribase: \
170 "https://git.draconx.ca/gitweb/homepage.git/blob/" +
172 filter :css_clean_selectors, \
173 preserve_comments: true, \
175 write @item.identifier.without_ext + '.css'
179 filter :copybin if @item.binary?
180 write @item.identifier.to_s
183 layout '/**/*.xsl', :xsl