1 # Nick's web site: Generate a project page from a submodule README.md
3 # Copyright © 2021 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[:title].downcase)
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 ;;" +
27 raise "git submodule foreach failed" if status != 0
29 gituri, contents = data.split("\n", 2)
30 intro, contents = contents.split("#", 2)
31 contents = if contents.nil? then "" else "\n#" + contents end
33 gitweb = gituri.sub(%r{^[^/]*(.*)(/.*)}, '\1/gitweb\2')
36 # Obtaining #{item[:title]}
39 if item[:release].nil?
41 There are presently no released versions of #{shortname}.
48 The latest development sources [may be browsed online](#{gitweb}) or
49 cloned directly using git, e.g.,
51 <kbd>git clone #{gituri}</kbd>
54 return intro + obtaining + contents