aboutsummaryrefslogtreecommitdiff
path: root/gemini-to-web
diff options
context:
space:
mode:
authoralex <alex@pdp7.net>2026-02-15 13:03:53 +0100
committeralex <alex@pdp7.net>2026-02-15 13:04:25 +0100
commit450ab7acd717d8c326c2a7c60a8cc4f1e7993a41 (patch)
tree7b4a60a56eee24cbaeb8e8c45b0a093f81da9e13 /gemini-to-web
parentb852f3f4171e5084b28335b3e885887d669da7e1 (diff)
Add example gemtext manipulation
Diffstat (limited to 'gemini-to-web')
-rw-r--r--gemini-to-web/README.md32
1 files changed, 32 insertions, 0 deletions
diff --git a/gemini-to-web/README.md b/gemini-to-web/README.md
index ad9476c..586a33d 100644
--- a/gemini-to-web/README.md
+++ b/gemini-to-web/README.md
@@ -53,3 +53,35 @@ You can use `coppewebite-indexer` to create a gemlog index automatically.
`coppewebite-to-rss` reads from standard input a gemtext file and produces the equivalent RSS to the gemtext subscription.
Refer to the [`example`](example) directory for an example.
+
+## Writing gemtext manipulations
+
+You can also use the parser to build tools that manipulate gemtext.
+For example:
+
+```python
+# /// script
+# dependencies = [
+# "gemini_to_web @ git+https://ñix.es/cgit/alex/coppewebite.git/#subdirectory=gemini-to-web",
+# ]
+# ///
+import pathlib
+
+from gemini_to_web import parser
+
+
+for gmi in pathlib.Path("source").glob("**/*.gmi"):
+ parsed = parser.parse(gmi.read_text())
+ parsed = list(parsed)
+ for i, line in enumerate(parsed):
+ match line:
+ case parser.LinkLine(url, link_name):
+ if url.startswith("/") and url.endswith(".gmi"):
+ parsed[i] = parser.LinkLine(url.removesuffix(".gmi"), link_name)
+ case _:
+ pass
+ gmi.write_text("\n".join(map(str, parsed)))
+```
+
+This script removes `.gmi` from link URLs in `source/**/*.gmi`.
+This script uses script dependencies that [`uv run` can use](https://docs.astral.sh/uv/guides/scripts/#creating-a-python-script).