Page meta

@meta

Thoughts on developing and using a microblog

https://github.com/SarahAlroe/gohost/

Page meta @meta 13 Sept 2026, at 22:58 Page meta @meta

Page meta @meta 13 Sept 2026, at 21:59

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…

The auto-generated snippets in editor.
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.


Page meta @meta 13 Sept 2026, at 22:58

Oh I’m having a bit of fun with this. Added another one for autogenerating shortcode snippets. Currently only clever enough to add a closing tag if the file uses .Inner, but hey, still an improvement to ease of writing.

Read More

I added glob matching to manage if different themes are used:

#!/usr/bin/env python3

import os
import glob
import json

snippetObj = dict()

for path in glob.glob(r"./themes/*/layouts/*shortcodes"):
    for root, dirs, files in os.walk(path):
        for n in files:
            fp = os.path.join(root, n)
            with open(fp, "r", errors="ignore") as f:
                shortcodeName = n.replace(".html", "")
                print(shortcodeName)
                body = "{\{<"+shortcodeName+" ${1:$TM_SELECTED_TEXT} >}}"
                if '.Inner' in f.read():
                    body = "{\{<"+shortcodeName+" $1 >}}\n${2:$TM_SELECTED_TEXT}\n{\{</"+shortcodeName+" >}}"
                snippetObj[shortcodeName] = {
                    "scope": "markdown",
                    "prefix": shortcodeName,
                    "body": body
                }
            
with open(".vscode/shortcodes.code-snippets", "w") as f:
    f.write(json.dumps(snippetObj, indent=4))

Oh right… Not executing but correctly rendering a shortcode within a code tag within a shortcode is apparently just not an easy thing. I gave up, if you wanna use the code above, remove the added backspaces within the curly brackets…

About the cleverness of the script, it might be easiest to just have a comment in each shortcode with the snippet body specified…