Skip to article frontmatterSkip to article content

Better blog lists with the MyST AST

On my journey to learn more about writing with the new MyST engine, I built upon my recent update to my blog infrastructure and made some improvements to my blog post list. Here’s what it looks like now:

Here’s a quick rundown of what I’ve improved.

Use the MyST sandbox to determine what AST to generate

I realized that MyST cards are a first-class citizen in the AST, meaning that I should be able to generate them directly with my Python plugin. These look a lot nicer than a list of bullet points.

However, generating MyST AST from scratch is cumbersome, so I headed over to the MyST sandbox to quickly see what the AST needed to look like for card outputs.

Using the sandbox to preview what the AST looks like.
Here’s an example of a card directive in the MyST sandbox.

Using the sandbox to preview what the AST looks like. Here’s an example of a card directive in the MyST sandbox.

With this in mind, I simply modified my blogpost Python script to generate AST like the above rather than the bulleted list I was generating before.

Generating output manually with MyST AST takes some getting used-to, but the sandbox-based workflow above helps a lot. I think it’ll be way nicer once we can do this programmatically with Jupyter cells, here’s the issue tracking parsing cell outputs as MyST and this one specifically about generating AST from notebook cells.