about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2024-10-04 17:38:06 +0900
committerNguyễn Gia Phong <cnx@loang.net>2024-10-04 17:44:01 +0900
commit09dac2bad71206c8ec4a0fe04c734e01d7876066 (patch)
treed71a999c3cef16a3897e70f4b38f35e8d135c6ba
parente348476a62f1a14f3f1818bb95de61f1d836c667 (diff)
downloadpx-09dac2bad71206c8ec4a0fe04c734e01d7876066.tar.gz
Quote URL in atom:id
-rw-r--r--Makefile2
-rwxr-xr-xatom-encode-ids16
2 files changed, 17 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 63c5cd8..965a889 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ all: $(OUTPUTS)
 	xsltproc page.xslt $< > $@
 
 atom.xml: atom.xslt $(DATA) cc.svg by.svg sa.svg
-	xsltproc atom.xslt > atom.xml
+	xsltproc atom.xslt | ./atom-encode-ids > atom.xml
 
 clean:
 	rm -f atom.xml */{index.xhtml,*.small.jpg}
diff --git a/atom-encode-ids b/atom-encode-ids
new file mode 100755
index 0000000..79ac509
--- /dev/null
+++ b/atom-encode-ids
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+import re
+from urllib.parse import quote
+from sys import stdin, stdout
+
+ID_LINE = re.compile(r'(?P<open> +<id>)(?P<url>.+)(?P<close></id>)\n')
+
+
+def encode_id(line: str) -> str:
+    match = re.fullmatch(ID_LINE, line)
+    if match is None: return line
+    return '{open}{iri}{close}\n'.format(iri=quote(match.group('url'), ':/#'),
+                                         **match.groupdict())
+
+
+stdout.writelines(map(encode_id, stdin.readlines()))