[+] Add tags and categories to json

This commit is contained in:
Hykilpikonna
2021-12-26 19:21:12 -05:00
parent fdc6801060
commit b8b86bab61
2 changed files with 18 additions and 6 deletions
+10 -2
View File
@@ -52,8 +52,16 @@ if __name__ == '__main__':
tags = Counter([t for p in posts for t in p['tags']])
cats = Counter([p['category'] for p in posts if 'category' in p])
tags, cats = [[(k, c[k]) for k in c] for c in [tags, cats]]
print(tags, cats)
# Convert to json
json_text = '{\n' \
f' "tags": {json.dumps(tags, ensure_ascii=False)},\n' \
f' "categories": {json.dumps(cats, ensure_ascii=False)},\n' \
' "posts": [\n ' \
+ ',\n '.join(json.dumps(p, cls=Encoder, ensure_ascii=False) for p in posts) + '\n' \
' ]\n' \
'}'
mp = Path('content/generated/metas.json')
mp.parent.mkdir(exist_ok=True, parents=True)
mp.write_text(json.dumps(posts, cls=Encoder, ensure_ascii=False, indent=2), 'utf-8')
mp.write_text(json_text, 'utf-8')