diff options
author | LarsVomMars | 2024-12-26 23:41:15 +0100 |
---|---|---|
committer | LarsVomMars | 2024-12-26 23:41:15 +0100 |
commit | 70625ce62aba43e586901d340ae81c2830d9fbc6 (patch) | |
tree | cee316ca645864968753439aa241cf105d270617 /.scripts/transform.py |
init
Diffstat (limited to '.scripts/transform.py')
-rw-r--r-- | .scripts/transform.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/.scripts/transform.py b/.scripts/transform.py new file mode 100644 index 0000000..f66023d --- /dev/null +++ b/.scripts/transform.py @@ -0,0 +1,26 @@ +from pathlib import Path +from datetime import datetime + +def transform(path: Path): + last_write_date = path.stat().st_mtime + last_write_date = datetime.fromtimestamp(last_write_date).strftime("%Y-%m-%d") + print(f"Transforming {path} last modified at {last_write_date}") + content = path.read_text() + title = content.splitlines()[0][1:].strip() + print(f"Title: {title}") + content = f"""--- +title: "{title}" +pubDate: "{last_write_date}" +--- +{content} +""" + path.write_text(content) + pass + + +blogs = Path("./src/content/blog") +for blog in blogs.iterdir(): + if blog.is_dir(): + for blog_file in blog.iterdir(): + if blog_file.is_file(): + transform(blog_file)
\ No newline at end of file |