]> git.draconx.ca Git - homepage.git/blob - Rules
Update GPG instructions for packages.
[homepage.git] / Rules
1 #!/usr/bin/env ruby
2 #
3 # Copyright © 2018-2022 Nick Bowler
4 #
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.
9 #
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.
14 #
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/>.
17
18 preprocess do
19     system("git", "submodule", "update", "--init")
20
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/}
25     rescue Errno::EINVAL
26     end
27
28     commit = nil
29     Open3.popen2("git", "rev-parse", "HEAD") do |stdin, stdout, result|
30         stdin.close
31         val = stdout.gets
32         stdout.close
33         commit = val.chomp if result.value.success?
34     end
35
36     if commit then
37         @items.each do |item|
38             item[:gitrev] = commit if item_source(item)
39         end
40     end
41
42     @items.find_all('/weblog/*.md').each do |item|
43         item[:kind] ||= 'article'
44     end
45
46     @items.each do |item|
47         item[:created_at] ||=
48             item[:published] || File.stat(item.raw_filename).mtime
49         item[:updated_at] ||=
50             item[:updated] || File.stat(item.raw_filename).mtime
51     end
52
53     archivedirs = {}
54     @items.find_all('/archive/**/*').each do |item|
55         dir = File.dirname(item.identifier)
56         while dir != "/"
57             archivedirs[dir] = true
58             dir = File.dirname(dir)
59         end
60     end
61
62     archivedirs.keys.sort_by{ |s| -s.length }.each do |dir|
63         attrs = {
64             pattern: "#{dir}/*{,/index.lst}",
65             title: "Index of #{dir}",
66             gitrev: commit,
67         }
68
69         @items.create("", attrs, "#{dir}/index.lst")
70     end
71
72     create_wkd_items(@items["/pubring.gpg"])
73 end
74
75 postprocess do
76     # Gzip all text items for nginx http_static
77     if !ENV['GZIP_SITE'].to_s.empty?
78         reps = @items.flat_map(&:reps).each do |rep|
79             file = rep.raw_path
80             next if !file or rep.binary?
81
82             if system("gzip", "-ck9", file, [:out]=>[file + ".gz.tmp", "wb"])
83                 system("touch", "-r", file, file + ".gz.tmp")
84                 File.rename(file + ".gz.tmp", file + ".gz")
85             else
86                 File.unlink(file + ".gz.tmp")
87             end
88         end
89     end
90
91     # Register URLs for git-annex keys
92     unless (uribase = ENV['ANNEX_URI_BASE'].to_s.chomp("/")).empty?
93         Open3.popen2("git", "-c", "core.bare=false", "annex", "registerurl") do
94         |stdin, stdout, result|
95             @items.each do |item|
96                 next if item.raw_filename.nil?
97
98                 l = File.readlink(item.raw_filename)
99                 next unless l =~ %r{/annex/objects/}
100
101                 key = File.basename(l)
102
103                 # Find output reps corresponding to this key, if any
104                 item.reps.each do |rep|
105                     next if rep.raw_path.nil?
106                     next unless
107                         FileUtils.identical?(item.raw_filename, rep.raw_path)
108
109                     loop do
110                         STDOUT.write(stdout.read_nonblock(100))
111                     rescue EOFError, IO::WaitReadable
112                         break
113                     end
114
115                     stdin.printf("%s %s%s\n", key, uribase, rep.path)
116                 end
117             rescue Errno::EINVAL
118             end
119
120             stdin.close
121             loop do
122                 STDOUT.write(stdout.readpartial(100))
123             rescue EOFError
124                 break
125             end
126
127             unless (rc = result.value).success?
128                 printf("git annex registerurl failed: %s\n", rc.to_s)
129             end
130         end
131     end
132 end
133
134 compile '/**/index.lst' do
135     layout '/listing.erb'
136     layout '/default.xml'
137     layout '/default.xsl'
138     layout '/embed-svg.xsl'
139     filter :relativize_paths, type: :xml
140     filter :xhtml_compat, fix_doctype: true
141     write item.identifier.without_ext + ".xhtml"
142 end
143
144 compile '/license/gpl*.md' do
145     filter :kramdown, auto_ids: false, header_offset: -1
146     layout '/default.xml'
147     layout '/gpl.xsl'
148     layout '/default.xsl'
149     filter :relativize_paths, type: :xml
150     filter :xhtml_compat
151     write to_xhtml
152 end
153
154 compile '/**/*.md' do
155     filter :erb
156     filter :kramdown, auto_ids: false, header_offset: 1
157     snapshot :rawbody
158     layout '/default.xml'
159     layout '/default.xsl'
160     filter :relativize_paths, type: :xml
161     filter :xhtml_compat
162     write to_xhtml
163 end
164
165 compile '/license/cc*.sgml' do
166     filter :sgml2xml
167     layout '/creativecommons.xsl'
168     layout '/default.xml'
169     layout '/default.xsl', "section-links": "yes"
170     filter :relativize_paths, type: :xml
171     filter :xhtml_compat
172     write to_xhtml
173 end
174
175 compile '/license/cc*.xhtml' do
176     layout '/creativecommons.xsl'
177     layout '/default.xml'
178     layout '/default.xsl', "section-links": "yes"
179     filter :relativize_paths, type: :xml
180     filter :xhtml_compat
181     write to_xhtml
182 end
183
184 compile '/images/*.jpg', rep: :large do
185     w, h = FastImage.size(item.raw_filename)
186     filename = item.identifier.without_ext + '-t1200.' + item.identifier.ext
187     filter :imgresize, width: [w, 1200].min, height: [h, 1200].min, cache: filename
188     write filename
189 end
190
191 compile '/images/*.jpg', rep: :medium do
192     w, h = FastImage.size(item.raw_filename)
193     filename = item.identifier.without_ext + '-t800.' + item.identifier.ext
194     if w > 900 or h > 900
195         filter :imgresize, width: 800, height: 800, cache: filename
196         write filename
197     end
198 end
199
200 compile '/images/*.jpg', rep: :info do
201     filter :imginfo
202     layout '/imginfo.xsl'
203     layout '/default.xml'
204     layout '/default.xsl'
205     filter :relativize_paths, type: :xml
206     filter :xhtml_compat
207     write to_xhtml
208 end
209
210 compile '/**/*.scss' do
211     filter :sass, syntax: :scss
212     filter :css_source, uribase: \
213         "https://git.draconx.ca/gitweb/homepage.git/blob/" +
214         @item[:gitrev] + ":"
215     filter :css_clean_selectors, \
216         preserve_comments: true, \
217         preserve_hacks: true
218     write @item.identifier.without_ext + '.css'
219 end
220
221 compile '/gpg/*' do
222     filter :wkd_export, armor: true
223     write "/pubring/" + @item.identifier.components.last + ".asc"
224 end
225
226 compile '/gpg/*', rep: :hu do
227     filter :wkd_export
228     write "/pubring/wkd/" + @item[:wkd_hash]
229 end
230
231 compile '/*.gpg' do
232 end
233
234 compile '/**/*.svg' do
235     filter :scour, comment_stripping: true
236     write @item.identifier.to_s
237 end
238
239 compile '/icons/**/*.svg', rep: :icon32 do
240     filter :svg2png, width: 32, height: 32
241     write @item.identifier.without_ext + "-32.png"
242 end
243
244 compile '/**/*' do
245     filter :copybin if @item.binary?
246     write @item.identifier.to_s
247 end
248
249 layout '/**/*.xsl', :xsl
250 layout '/**/*', :erb