I wrote a little python script using the frontmatter package to generate a vs code snippets file from the tags of existing posts, so that I can ctrl + space in the frontmatter to add existing tags. I’m enjoying the whole infrastructure building thing…

Read More
The script for anyone curious:
#!/usr/bin/env python3
import os
import frontmatter
import json
tags = set()
for root, dirs, files in os.walk(r"./content/"):
for n in files:
fp = os.path.join(root, n)
with open(fp, "r", errors="ignore") as f:
post = frontmatter.load(f)
if 'tags' in post:
for tag in post['tags']:
if tag:
tags.add(tag)
print(tags)
snippetObj = dict()
for tag in tags:
snippetObj[tag] = {
"scope": "yaml",
"prefix": tag,
"body": "- " + tag
}
with open(".vscode/tags.code-snippets", "w") as f:
f.write(json.dumps(snippetObj, indent=4))
And then "runOn": "folderOpen" in the tasks.json to make it rebuild on opening the editor.
