Including code in blog posts

Including code snippets into a blog post, such as my recent post switching a Hugo theme typically means copy-pasting snippets into your blog post text, surrounded with code fences, but makes the code unusable (it can no longer be compiled or analyzed). Similarly with the output of any given command, log file, etc. Thus, we keep the canonical copy of the code (or the output) in an external file, and have to periodically manually copy-paste the content back into the blog post, but of course, if we forget, it’s out of date. What if we fix a bug in the code, and forget to include that fix into the blog post? Inaccuracies will confuse our future readers. How can we automate this process? ...

May 31, 2019