import json import frontmatter import os def dump(): # list all the folders folders = [ name for name in os.listdir() if os.path.isdir(os.path.join("", name)) and not name.startswith(".") and not name == "miri-the-leader" ] print(folders) contents = [] for folder in folders: with open(f"{folder}/contents.md", "r") 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"], } else: postit = {"title": metadata["title"], "description": content} contents.append(postit) with open("postit/contents.json", "w") as f: f.write(json.dumps(contents))