spanskiblog/scripts/move.py

42 lines
1.2 KiB
Python

import os
import time
header = {
"author": "spanskiduh",
}
MD_NOTES_DIR = "../../../md-notes/"
POSTS_DIR = "../content/posts/"
def main():
# List all files in md-notes directory
for filename in os.listdir(MD_NOTES_DIR):
# Check if file is md file
if filename.endswith(".md"):
# Opent the file and read it
with open(MD_NOTES_DIR + filename, "r") as f:
# Read the file
file = f.read()
header["title"] = filename[:-3]
header["description"] = f"click to read about {filename[:-3]}"
date_modified = os.path.getmtime(MD_NOTES_DIR + filename)
header["date"] = time.strftime("%Y-%m-%d", time.localtime(date_modified))
# Add the header to the file for hugo to parse
file = f"""\r
+++
date="{header["date"]}"
author="{header["author"]}"
title="{header["title"]}"
description="{header["description"]}"
+++
{file}"""
# Write the file to proc directory
with open(POSTS_DIR + filename, "w") as f:
f.write(file)
if __name__ == '__main__':
main()