]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
More release improvements.
authorWayne Davison <wayne@opencoder.net>
Sun, 14 Jun 2020 04:10:13 +0000 (21:10 -0700)
committerWayne Davison <wayne@opencoder.net>
Sun, 14 Jun 2020 04:21:26 +0000 (21:21 -0700)
packaging/md2html [new file with mode: 0755]
packaging/release-rsync

diff --git a/packaging/md2html b/packaging/md2html
new file mode 100755 (executable)
index 0000000..f0f61cd
--- /dev/null
@@ -0,0 +1,87 @@
+#!/usr/bin/python3
+
+# Copyright (C) 2020 Wayne Davison
+#
+# This program is freely redistributable.
+
+import re, argparse
+
+HTML_START = """\
+<html><head>
+<title>%s</title>
+<link href="https://fonts.googleapis.com/css2?family=Roboto&family=Roboto+Mono&display=swap" rel="stylesheet">
+<style>
+body {
+  max-width: 50em;
+  margin: auto;
+}
+body, b, strong, u {
+  font-family: 'Roboto', sans-serif;
+}
+code {
+  font-family: 'Roboto Mono', monospace;
+  font-weight: bold;
+}
+pre code {
+  display: block;
+  font-weight: normal;
+}
+blockquote pre code {
+  background: #f1f1f1;
+}
+dd p:first-of-type {
+  margin-block-start: 0em;
+}
+</style>
+</head><body>
+"""
+
+HTML_END = """\
+</body></html>
+"""
+
+md_parser = None
+
+def main():
+    for mdfn in args.mdfiles:
+        title = re.sub(r'.*/', '', mdfn).replace('.md', '')
+        htfn = mdfn.replace('.md', '.html')
+
+        print("Parsing", mdfn, '->', htfn)
+
+        with open(mdfn, 'r', encoding='utf-8') as fh:
+            txt = fh.read()
+
+        html = md_parser(txt)
+
+        with open(htfn, 'w', encoding='utf-8') as fh:
+            fh.write(HTML_START % title)
+            fh.write(html)
+            fh.write(HTML_END)
+
+
+def html_via_cmarkgfm(txt):
+    return cmarkgfm.markdown_to_html(txt)
+
+
+def html_via_commonmark(txt):
+    return commonmark.HtmlRenderer().render(commonmark.Parser().parse(txt))
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser(description='Output html for md pages.', add_help=False)
+    parser.add_argument("--help", "-h", action="help", help="Output this help message and exit.")
+    parser.add_argument("mdfiles", nargs='+', help="The .md files to turn into .html files.")
+    args = parser.parse_args()
+
+    try:
+        import cmarkgfm
+        md_parser = html_via_cmarkgfm
+    except:
+        try:
+            import commonmark
+            md_parser = html_via_commonmark
+        except:
+            die("Failed to find cmarkgfm or commonmark for python3.")
+
+    main()
index ee771bd03c75cd144d3077c7acfeff235f87b0be..a4c193c62191fc5f54558fe775f80b96c0f4c3f0 100755 (executable)
@@ -329,13 +329,18 @@ About to:
     shutil.rmtree(rsync_ver)
 
     print(f"Updating the other files in {dest} ...")
-    cmd_chk('rsync -a README.md NEWS.md OLDNEWS.md TODO'.split() + [dest])
-    if os.path.lexists(news_file):
-        os.unlink(news_file)
-    os.link(f"{dest}/NEWS.md", news_file)
-    cmd_chk(f"git log --name-status | gzip -9 >{dest}/ChangeLog.gz")
+    md_files = 'README.md NEWS.md OLDNEWS.md'.split()
+    html_files = [ fn for fn in gen_files if fn.endswith('.html') ]
+    cmd_chk(['rsync', '-a', *md_files, *html_files, dest])
+    cmd_chk(["packaging/md2html"] + [ dest +'/'+ fn for fn in md_files ])
+
+    for topfn, verfn in (('NEWS.md', news_file), ('NEWS.html', news_file.replace('.md', '.html'))):
+        topfn = dest + '/' + topfn
+        if os.path.lexists(verfn):
+            os.unlink(verfn)
+        os.link(topfn, verfn)
 
-    cmd_chk(['rsync', '-a', *glob.glob('*.[1-9].html'), os.path.join(dest, html_fn)])
+    cmd_chk(f"git log --name-status | gzip -9 >{dest}/ChangeLog.gz")
 
     for fn in (srctar_file, pattar_file, diff_file):
         asc_fn = fn + '.asc'