For what it's worth, if you're using Pandoc, you can set the HTML output to be "standalone" based on a simple template.[0] You can also include a standard header and footer to be automatically inserted for each generated page.
I use a variation of this command in a bash script to generate my entire static site.[1] A friend improved upon my script with a Go implementation that does some more advanced stuff, but still compiles Markdown to HTML using this command under the hood.[2]
0: https://pandoc.org/MANUAL.html#option--standalone
1: https://github.com/jstrieb/personal-site/blob/master/compile...
2: https://github.com/lsnow99/dudu