]> xn--ix-yja.es Git - alex.git/commitdiff
WIP
authoralex <alex@pdp7.net>
Fri, 12 Mar 2021 19:58:44 +0000 (20:58 +0100)
committeralex <alex@pdp7.net>
Fri, 12 Mar 2021 19:58:44 +0000 (20:58 +0100)
.gitignore [new file with mode: 0644]
README
build.py [new file with mode: 0755]
fix.py [new file with mode: 0755]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..9163f26
--- /dev/null
@@ -0,0 +1,2 @@
+build
+md
diff --git a/README b/README
index 68200d07fe369463ed0d46cd33eec184e42b0fba..037b104ddf3dd80e775316478d30dad8f348583c 100644 (file)
--- a/README
+++ b/README
@@ -6,3 +6,4 @@ $ npx wordpress-export-to-markdown --input elblogesmo.WordPress.2021-03-12.xml -
 $ pipx install md2gemini
 
 $ find md -name '*.md' -execdir md2gemini -l at-end -w '{}' ';' 
+$ find md -name "*.md" -delete
diff --git a/build.py b/build.py
new file mode 100755 (executable)
index 0000000..97f55c0
--- /dev/null
+++ b/build.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+import os
+import shutil
+
+
+def build():
+    shutil.rmtree("build", ignore_errors=True)
+    os.makedirs("build/gmi")
+
+    for directory, _, files in os.walk("content"):
+        for file in files:
+            if file.endswith("gmi"):
+                new_dir = f"build/gmi/{directory[8:]}"
+                os.makedirs(new_dir, exist_ok=True)
+                shutil.copyfile(f"{directory}/{file}", f"{new_dir}/{file}")
+            else:
+                # FIXME
+                pass
+
+
+if __name__ == "__main__":
+    build()
diff --git a/fix.py b/fix.py
new file mode 100755 (executable)
index 0000000..b6fb222
--- /dev/null
+++ b/fix.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+import os
+import re
+import shutil
+
+
+def fix():
+    shutil.rmtree("content", ignore_errors=True)
+    os.makedirs("content")
+
+    for directory, _, files in os.walk("md"):
+        for file in files:
+            if file.endswith("gmi"):
+                new_dir = f"content/{directory[3:]}"
+                with open(f"{directory}/{file}", "r") as old_file:
+                    old_content = old_file.read()
+                old_content_lines = old_content.splitlines()
+
+                meta_line = old_content_lines[2]
+                match = re.fullmatch(r'''title: "([^"]*)" date: "(....-..-..)" categories:''', meta_line)
+                title = match.group(1)
+                date = match.group(2)
+
+                separator_line = old_content_lines[1:].index('-'*80) + 1
+
+                content = f"# {title}\n"
+                content += f"{date}\n"
+                content += "\n".join(old_content_lines[separator_line + 1:])
+
+                import pdb; pdb.set_trace()
+
+#                print(new_dir, file)
+#                os.makedirs(new_dir, exist_ok=True)
+#                shutil.copyfile(, f"{new_dir}/{file}")
+            else:
+                # FIXME
+                pass
+
+
+if __name__ == "__main__":
+    fix()