diff options
| author | alex <alex@pdp7.net> | 2023-10-13 16:02:34 +0200 |
|---|---|---|
| committer | alex <alex@pdp7.net> | 2023-10-13 16:03:35 +0200 |
| commit | 87df74b49c8792e9dddd550d862b2cfa9a2e909b (patch) | |
| tree | ce1013a2f9a4ac79a6f6e4d94b857c2900dead11 /fix.py | |
| parent | 4f86ec0553d659fe3253a92657d85a96734d0048 (diff) | |
Adapt to new layout
Diffstat (limited to 'fix.py')
| -rwxr-xr-x | fix.py | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/fix.py b/fix.py deleted file mode 100755 index 319d172f..00000000 --- a/fix.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/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:]) - - os.makedirs(new_dir, exist_ok=True) - with open(f"{new_dir}/{file}", "w") as new_file: - new_file.write(content) - else: - # FIXME - pass - - -if __name__ == "__main__": - fix() |
