]> git.draconx.ca Git - homepage.git/blob - Rules
5473788e31261cfed8b0bbe865e1ba88cf83545e
[homepage.git] / Rules
1 #!/usr/bin/env ruby
2 #
3 # Copyright © 2018-2020 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     # 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/}
23     rescue Errno::EINVAL
24     end
25
26     commit = nil
27     Open3.popen2("git", "rev-parse", "HEAD") do |stdin, stdout, result|
28         stdin.close
29         val = stdout.gets
30         stdout.close
31         commit = val.chomp if result.value.success?
32     end
33
34     if commit then
35         @items.each do |item|
36             item[:gitrev] = commit if item_source(item)
37         end
38     end
39 end
40
41 postprocess do
42     # Gzip all text items for nginx http_static
43     if !ENV['GZIP_SITE'].to_s.empty?
44         reps = @items.flat_map(&:reps).each do |rep|
45             file = rep.raw_path
46             next if !file or rep.binary?
47
48             if system("gzip", "-ck9", file, [:out]=>[file + ".gz.tmp", "wb"])
49                 system("touch", "-r", file, file + ".gz.tmp")
50                 File.rename(file + ".gz.tmp", file + ".gz")
51             else
52                 File.unlink(file + ".gz.tmp")
53             end
54         end
55     end
56 end
57
58 compile '/license/gpl*.md' do
59     filter :kramdown, auto_ids: false, header_offset: -1
60     layout '/default.xml'
61     layout '/gpl.xsl'
62     layout '/default.xsl'
63     filter :relativize_paths, type: :xml
64     filter :xhtml_compat
65     filter :remove_wj
66     write to_xhtml
67 end
68
69 compile '/**/*.md' do
70     filter :erb
71     filter :kramdown, auto_ids: false, header_offset: 1
72     snapshot :rawbody
73     layout '/default.xml'
74     layout '/default.xsl'
75     filter :relativize_paths, type: :xml
76     filter :xhtml_compat
77     filter :remove_wj
78     write to_xhtml
79 end
80
81 compile '/license/cc*.sgml' do
82     filter :sgml2xml
83     layout '/creativecommons.xsl'
84     layout '/default.xml'
85     layout '/default.xsl', "section-links": "yes"
86     filter :relativize_paths, type: :xml
87     filter :xhtml_compat
88     filter :remove_wj
89     write to_xhtml
90 end
91
92 compile '/license/cc*.xhtml' do
93     layout '/creativecommons.xsl'
94     layout '/default.xml'
95     layout '/default.xsl', "section-links": "yes"
96     filter :relativize_paths, type: :xml
97     filter :xhtml_compat
98     filter :remove_wj
99     write to_xhtml
100 end
101
102 compile '/**/*.scss' do
103     filter :sass, syntax: :scss
104     filter :css_source, uribase: \
105         "https://git.draconx.ca/gitweb/homepage.git/blob/" +
106         @item[:gitrev] + ":"
107     filter :css_clean_selectors, \
108         preserve_comments: true, \
109         preserve_hacks: true
110     write @item.identifier.without_ext + '.css'
111 end
112
113 compile '/**/*' do
114   filter :copybin if @item.binary?
115   write @item.identifier.to_s
116 end
117
118 layout '/**/*.xsl', :xsl
119 layout '/**/*', :erb