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.

47 lines
1.6 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()]
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 "img" in content:
postit = {
"title": metadata["title"],
"description": content["alt"],
"img": content["img"],
"slug": folder,
}
elif type(content) == dict and "card" in content:
postit = {
"title": metadata["title"],
"card": content["card"],
"quote": content["quote"],
"motivation": content["motivation"],
"vision": content["vision"],
"emphaty": content["emphaty"],
"positivity": content["positivity"],
"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))