aboutsummaryrefslogtreecommitdiff
path: root/from_old_blog_slugs.py
diff options
context:
space:
mode:
authoralex <alex@pdp7.net>2023-10-13 16:02:34 +0200
committeralex <alex@pdp7.net>2023-10-13 16:03:35 +0200
commit87df74b49c8792e9dddd550d862b2cfa9a2e909b (patch)
treece1013a2f9a4ac79a6f6e4d94b857c2900dead11 /from_old_blog_slugs.py
parent4f86ec0553d659fe3253a92657d85a96734d0048 (diff)
Adapt to new layout
Diffstat (limited to 'from_old_blog_slugs.py')
-rw-r--r--from_old_blog_slugs.py58
1 files changed, 0 insertions, 58 deletions
diff --git a/from_old_blog_slugs.py b/from_old_blog_slugs.py
deleted file mode 100644
index f1d0b579..00000000
--- a/from_old_blog_slugs.py
+++ /dev/null
@@ -1,58 +0,0 @@
-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)