]> git.draconx.ca Git - homepage.git/blob - lib/project-readme.rb
Generate slotifier project page from bundled README.md.
[homepage.git] / lib / project-readme.rb
1 # Nick's web site: Generate a project page from a submodule README.md
2 #
3 # Copyright © 2021 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 def project_readme(item = @item)
19     tag = item.fetch(:release, "HEAD")
20     shortname = item.fetch(:shortname, item[:title].downcase)
21
22     data, status = Open3.capture2("git", "submodule", "foreach", "--quiet",
23       "case $sm_path in */" + item[:module] + ")" +
24       "git remote get-url origin || echo;" +
25       "git show " + tag + ":README.md ;;" +
26       "esac")
27     raise "git submodule foreach failed" if status != 0
28
29     gituri, contents = data.split("\n", 2)
30     intro, contents = contents.split("#", 2)
31     contents = if contents.nil? then "" else "\n#" + contents end
32
33     gitweb = gituri.sub(%r{^[^/]*(.*)(/.*)}, '\1/gitweb\2')
34
35     obtaining = <<~EOF
36         # Obtaining #{item[:title]}
37     EOF
38
39     if item[:release].nil?
40         obtaining += <<~EOF
41             There are presently no released versions of #{shortname}.
42         EOF
43     else
44         # TODO
45     end
46
47     obtaining += <<~EOF
48         The latest development sources [may be browsed online](#{gitweb}) or
49         cloned directly using git, e.g.,
50
51         <kbd>git clone #{gituri}</kbd>
52     EOF
53
54     return intro + obtaining + contents
55 end