You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB
Python

import json
import frontmatter
import os
def dump():
# list all the folders
path = "postit/static/contents"
folders = [
f.name for f in os.scandir(path) if f.is_dir() and f.name != "miri-the-leader"
]
contents = []
for folder in folders:
with open(f"{path}/{folder}/contents.md", "r", encoding="utf8") as f:
metadata, body = frontmatter.parse(f.read())
for content in metadata["contents"]:
if type(content) == dict and content["img"]:
postit = {
"title": metadata["title"],
"description": content["alt"],
"img": content["img"],
"slug": folder,
}
else:
postit = {
"title": metadata["title"],
"description": content,
"slug": folder,
}
contents.append(postit)
with open("postit/contents.json", "w") as f:
f.write(json.dumps(contents))