1 # Nick's web site: Generate a project page from a submodule README.md
3 # Copyright © 2021-2022 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/>.
18 def project_readme(item = @item)
19 tag = item.fetch(:release, "HEAD")
20 shortname = item.fetch(:shortname, item[:module])
22 data, status = Open3.capture2("git", "submodule", "foreach", "--quiet",
23 "case $sm_path in */" + item[:module] + ")" +
24 "git fetch --quiet --tags;" +
25 "git log --max-count=1 --format=%cI #{tag}; printf '\\35';" +
26 "git show #{tag}:NEWS 2>/dev/null; printf '\\35';" +
27 "git remote get-url origin; printf '\\35';" +
28 "git show #{tag}:README.md ;;" +
30 raise "git submodule foreach failed" if status != 0
32 date, news, gituri, contents = data.split("\35", 4)
33 intro, contents = contents.split("#", 2)
34 contents = if contents.nil? then "" else "\n#" + contents end
37 gitweb = gituri.sub(%r{^[^/]*(.*)(/.*)}, '\1/gitweb\2')
38 date = Date.iso8601(date).to_time
41 # Obtaining #{item[:title]}
44 if item[:release].nil?
45 obtaining += "\n" + <<~EOF
46 There are presently no released versions of #{shortname}.
49 newsver, news = news.split("\n", 2)
50 newsver.sub!(/^.*?([[:digit:]][^:]*).*$/, '\1')
52 targz = "#{shortname}-#{newsver}.tar.gz"
53 distbase = "/archive/#{shortname}"
55 [archive]: #{distbase}
57 All released files are available from the [#{shortname} archive
63 The latest development sources [may be browsed online](#{gitweb}) or
64 cloned directly using git, e.g.,
66 <kbd>git clone #{gituri}</kbd>
69 unless item[:release].nil?
70 obtaining += "\n" + <<~EOF
71 [targz]: #{distbase}/#{targz}
72 [targzsig]: #{distbase}/#{targz}.sig
74 The most recent release is version #{newsver}, released on
75 #{date.getutc.strftime("%Y-%m-%d")}. Source code for this version
76 is available in [#{targz}][targz] ([signature][targzsig]).
77 Noteworthy changes in this release:
80 news.each_line do |line|
81 break if line =~ /^[^[:space:]]/
82 obtaining += line.lstrip
85 gpg_keyid = "5B45D3D185B8E1F6"
86 obtaining += "\n\n" + <<~EOF
87 [gpg]: https://gnupg.org/
88 [keyring]: /pubring/#{gpg_keyid}.asc
90 Use the signature file to verify that the corresponding source
91 bundle is intact. After downloading both files, if [GnuPG][gpg]
92 is installed, the signature can be verified with a command like:
94 <kbd>gpg --verify #{targz}.sig #{targz}</kbd>
96 If the verification fails because you don't have the required
97 public key, that key can be imported with a command such as:
99 <kbd>gpg --keyserver keys.draconx.ca --recv-keys #{gpg_keyid}</kbd>
101 Then run the verify command again. Alternatively, you can
102 [download the public keyring][keyring] manually and import it
103 using `gpg --import`.
107 return "#{intro}\n\n#{obtaining}\n\n#{contents}"