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
55 # Gzip all text items for nginx http_static
56 if !ENV['GZIP_SITE'].to_s.empty?
57 reps = @items.flat_map(&:reps).each do |rep|
59 next if !file or rep.binary?
61 if system("gzip", "-ck9", file, [:out]=>[file + ".gz.tmp", "wb"])
62 system("touch", "-r", file, file + ".gz.tmp")
63 File.rename(file + ".gz.tmp", file + ".gz")
65 File.unlink(file + ".gz.tmp")
70 # Register URLs for git-annex keys
71 unless (uribase = ENV['ANNEX_URI_BASE'].to_s.chomp("/")).empty?
72 Open3.popen2("git", "annex", "registerurl") do |stdin, stdout, result|
74 l = File.readlink(item.raw_filename)
75 next unless l =~ %r{/annex/objects/}
77 key = File.basename(l)
79 # Find output reps corresponding to this key, if any
80 item.reps.each do |rep|
82 FileUtils.identical?(item.raw_filename, rep.raw_path)
85 STDOUT.write(stdout.read_nonblock(100))
86 rescue EOFError, IO::WaitReadable
90 stdin.printf("%s %s%s\n", key, uribase, rep.path)
97 STDOUT.write(stdout.readpartial(100))
102 unless (rc = result.value).success?
103 printf("git annex registerurl failed: %s\n", rc.to_s)
109 compile '/license/gpl*.md' do
110 filter :kramdown, auto_ids: false, header_offset: -1
111 layout '/default.xml'
113 layout '/default.xsl'
114 filter :relativize_paths, type: :xml
120 compile '/**/*.md' do
122 filter :kramdown, auto_ids: false, header_offset: 1
124 layout '/default.xml'
125 layout '/default.xsl'
126 filter :relativize_paths, type: :xml
132 compile '/license/cc*.sgml' do
134 layout '/creativecommons.xsl'
135 layout '/default.xml'
136 layout '/default.xsl', "section-links": "yes"
137 filter :relativize_paths, type: :xml
143 compile '/license/cc*.xhtml' do
144 layout '/creativecommons.xsl'
145 layout '/default.xml'
146 layout '/default.xsl', "section-links": "yes"
147 filter :relativize_paths, type: :xml
153 compile '/images/*.jpg', rep: :large do
154 filename = item.identifier.without_ext + '-t1200.' + item.identifier.ext
155 filter :imgresize, width: 1200, height: 1200, cache: filename
159 compile '/images/*.jpg', rep: :info do
161 layout '/imginfo.xsl'
162 layout '/default.xml'
163 layout '/default.xsl'
164 filter :relativize_paths, type: :xml
170 compile '/**/*.scss' do
171 filter :sass, syntax: :scss
172 filter :css_source, uribase: \
173 "https://git.draconx.ca/gitweb/homepage.git/blob/" +
175 filter :css_clean_selectors, \
176 preserve_comments: true, \
178 write @item.identifier.without_ext + '.css'
182 filter :copybin if @item.binary?
183 write @item.identifier.to_s
186 layout '/**/*.xsl', :xsl