]> git.draconx.ca Git - homepage.git/blobdiff - lib/project-readme.rb
Generate slotifier project page from bundled README.md.
[homepage.git] / lib / project-readme.rb
diff --git a/lib/project-readme.rb b/lib/project-readme.rb
new file mode 100644 (file)
index 0000000..1e1fa87
--- /dev/null
@@ -0,0 +1,55 @@
+# Nick's web site: Generate a project page from a submodule README.md
+#
+# Copyright © 2021 Nick Bowler
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+def project_readme(item = @item)
+    tag = item.fetch(:release, "HEAD")
+    shortname = item.fetch(:shortname, item[:title].downcase)
+
+    data, status = Open3.capture2("git", "submodule", "foreach", "--quiet",
+      "case $sm_path in */" + item[:module] + ")" +
+      "git remote get-url origin || echo;" +
+      "git show " + tag + ":README.md ;;" +
+      "esac")
+    raise "git submodule foreach failed" if status != 0
+
+    gituri, contents = data.split("\n", 2)
+    intro, contents = contents.split("#", 2)
+    contents = if contents.nil? then "" else "\n#" + contents end
+
+    gitweb = gituri.sub(%r{^[^/]*(.*)(/.*)}, '\1/gitweb\2')
+
+    obtaining = <<~EOF
+        # Obtaining #{item[:title]}
+    EOF
+
+    if item[:release].nil?
+        obtaining += <<~EOF
+            There are presently no released versions of #{shortname}.
+        EOF
+    else
+        # TODO
+    end
+
+    obtaining += <<~EOF
+        The latest development sources [may be browsed online](#{gitweb}) or
+        cloned directly using git, e.g.,
+
+        <kbd>git clone #{gituri}</kbd>
+    EOF
+
+    return intro + obtaining + contents
+end