Archive pages with shortcodes?

I’ve found hugo super-helpful with my niche application:

I generate one or more pages specific to each week. As I learn more about hugo/go I’m able to improve my shortcodes. But as I do so, older pages using those shortcodes all need to be caught up to the new usage pattern. That’s a lot of work!

What I want to do is find a way to “fix” old pages so that the way the shortcodes render today is how they will always render – even if I change the shortcode it relies upon.

Put another way, I want to render-once my older pages and eliminate their dependence upon shortcodes.

For example:

  • In 2020 I build page A that relies on shortcode s and t
  • In 2021 I archive page A so that it will not change
  • In 2022 I eliminate shortcode s, folding it into t; page A doesn’t change.
  • In 2022 I change shortcode t to work differently in page B; page A still renders as it did in 2020

Is there any natural way to do this using tools already available in the hugo ecosystem?


I can think of two ways to handle this:

  1. Version your shortcode names (t-v2, s-v2, etc)
  2. Include conditional logic based on something (year, front matter, etc.).

Thanks for the quick response!

I was thinking along those lines, too – I even do some of it on a small scale.

One simple way to version (and contain) shortcut names could be to have years in the root of the shortcodes directory and copy them forward each year to make changes.

But multiplying code in the shortcode (to provide different functionality depending on what version the page expects) or multiplying files in the shortcode directories (already a bit hairy) are both bad habits making my (relatively simple) site more difficult to use and maintain already.

So I’d really like to just break the older pages’ dependence shortcodes so I can eliminate/consolidate/simplify/improve the shortcodes in use for future pages.

Obviously this is not really an hugo problem, but a problem with the way I have chosen to use and abuse hugo. :slight_smile:

I considered copying the generated .html files over into the content directory to replace my .md originals. But I worry about them having the appropriate frontmatter and then I notice all the files would have to renamed from index.html.

So I guess what I’d really like to do is to render the shortcodes into pure markdown to replace my original .md source files. Or, perhaps more generically, to replace all my go {{ templates }} with the markdown they generate.