From b0ee17e4dfcdbed862e80dbb4d684fa6d82f1a80 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 5 Mar 2023 21:10:04 +0000 Subject: Fix eucaliptus.ath.cx blog links --- from_old_blog_slugs.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 from_old_blog_slugs.py (limited to 'from_old_blog_slugs.py') diff --git a/from_old_blog_slugs.py b/from_old_blog_slugs.py new file mode 100644 index 00000000..f1d0b579 --- /dev/null +++ b/from_old_blog_slugs.py @@ -0,0 +1,58 @@ +import pathlib +import re +import subprocess +import yaml + + +def slug(s): + orig = s + s = re.sub(r"""[*\^/\-":+#.,¿?¡!()[\]'%]+""", " ", s) + s = s.strip() + s = re.sub(" +", "-", s) + s = s.lower() + acc = { + "áà": "a", + "éè": "e", + "íì": "i", + "óò": "o", + "úùü": "u", + "ñ": "n", + "ç": "c", + } + for ds, r in acc.items(): + for d in ds: + s = s.replace(d, r) + assert re.match(r"^[a-z0-9\-]+$", s), (orig, s) + return s + + +with open("post.yml") as f: + posts = yaml.load(f) + +posts = [dict(post) for post in posts] + +replacements = {} + +for post in posts: + post["post"] = post["post"].encode("iso-8859-1").decode("utf8") + post["title"] = post["title"].encode("iso-8859-1").decode("utf8") + + post["post"] = post["post"].replace("\\r\\n", " ") + + t = post["title"] + + y,m,d = post["posted"].split(" ")[0].split("-") + +# print(f"http://eucaliptus.ath.cx/~alex/blog/?query=byId&postId={post['id']}", f"gemini://alex.corcoles.net/{y}/{m}/{slug(post['title'])}/") + replacements[f"http://eucaliptus.ath.cx/~alex/blog/?query=byId&postId={post['id']}"] = f"gemini://alex.corcoles.net/{y}/{m}/{slug(post['title'])}/" + replacements[f"https://eucaliptus.ath.cx/~alex/blog/?query=byId&postId={post['id']}"] = f"gemini://alex.corcoles.net/{y}/{m}/{slug(post['title'])}/" + replacements[f"?query=byId&postId={post['id']}"] = f"gemini://alex.corcoles.net/{y}/{m}/{slug(post['title'])}/" + + +for f in pathlib.Path("content/").glob("**/*.gmi"): + with open(f) as fp: + post = fp.read() + for i, o in replacements.items(): + post = post.replace(i + " ", o + " ") + with open(f, "w") as fp: + fp.write(post) -- cgit v1.2.3