From d85a1e4e2eaa340dc83938bfda33bf2a9e7f50f6 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Sun, 11 Jul 2021 21:14:59 +0000 Subject: More git link cleanup * Fix Trac "export:" links * Use "about" link for naked repository links so default view is the README.md * Adjust to match new cgit configuration which hides ".git" suffixes --- kludge-cgit-urls.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 kludge-cgit-urls.py (limited to 'kludge-cgit-urls.py') diff --git a/kludge-cgit-urls.py b/kludge-cgit-urls.py new file mode 100755 index 0000000..9d9feed --- /dev/null +++ b/kludge-cgit-urls.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# +# Kludges specific to converting the Cryptech wiki + +import os, re, json + +with open("repositories.json") as f: + repo_or = "|".join(os.path.splitext(r)[0] for r in json.load(f)) + +plain = "](https://git.cryptech.is" +export = "](export:/" +regexp = re.compile(r"(\(https://git\.cryptech\.is/(?:" + repo_or + "))([(/)])") + +for root, dirs, files in os.walk("pelican/content"): + for fn in files: + if not fn.endswith(".md"): + continue + fn = os.path.join(root, fn) + with open(fn) as f: + lines = f.readlines() + if not any(plain in line or export in line for line in lines): + continue + changes = 0 + for i, line in enumerate(lines): + if export in line: + changes = 1 + line = line.replace(export, "](https://git.cryptech.is/") + elif plain not in line: + continue + lines[i], n = regexp.subn( + lambda m: m.group(1) + ("/tree" if m.group(2) == "/" else "/about") + m.group(2), + line) + changes += n + if changes: + tn = fn + ".tmp" + with open(tn, "w") as f: + for line in lines: + f.write(line) + os.rename(tn, fn) -- cgit v1.2.3