Effectively export content that contains Hugo shortcodes for use with another framework

Shortcodes are one of Hugo’s most powerful features—and one of my personal favorites—but they have one major drawback: they tether content to a single generator.

Let’s say I have a website created in Hugo with 1000 content files (i.e., .md), all with YAML metadata, most of which instances of 3-4 (HTML) shortcodes created for that specific project. I may want to move 300 files from this project to a new site built with another framework, but as the content stands, I’m stuck with multiple {{%%}} written to the body copy of my page.

Anyone have suggestions on how to render these HTML blocks directly to the content of the markdown files if I need to drop the content into another generator?

Note: This is still in the hypothetical phase and therefore may be bettered labeled as a feature request.

Output the entries with a template onto a single page and break the entries into files with CSPLIT. I can give you more details on how to do this, if it sounds like something feasible to you.

Thanks @budparr With respect to the template, how do you recommend keeping the markdown surrounding the shortcode in markdown while having only the shortcode render to HTML?

I was thinking that the whole thing could be in markdown. I guess you’re looking to keep the more elaborate figure etc of the shortcode. I suppose (just thinking out loud), I’d convert it all then convert the images back with some regex. Wouldn’t be hard, but certainly may be better ways.

1 Like

@budparr I like the ND article you wrote related to this. Full disclosure: the idea is selling a business on JAMStack and Hugo in particular because of features like shortcodes. The problem is having two competing arguments:

  1. All your content is portable in markdown
  2. Unless it includes shortcodes

For anyone in the future that stumbles up on this thread and wants to read Bud’s article:

1 Like

Thanks, @rdwatters. But, what am I missing. I haven’t tried, but it seems like a problem that 15 minutes of fiddling around with Regex can solve, no?

I think you’re right, and as always, I appreciate the feedback.

What I’m looking for is probably a Hugo export command that renders all shortcodes in content/markdown files while keeping everything else as is. I’d probably do it with Pandoc, custom outputs or maybe even bash (or your very nice solution in the article above).

I should have been more transparent that my interests are to keep this as friendly as possible to content authors who fall somewhere on the lower end of the writer=>developer spectrum.

I think a “Hugo export command” would be a tough sell. I understand the need, but that will have to live outside of Hugo. There is very little product-lockin with Hugo, and it is easily solved with some simple replacement scripts. We welcome more “import Jekyll” commands, but you will never see a “export to Jekyll command”. Hope that goes without saying. :slight_smile:

Haha, of course. I don’t plan on leaving Hugo anytime soon :smile: I even use it for my daily notes. And I agree about there being very little product lock-in. This is more about appealing to people who don’t even know what Hugo, Jekyll, or Hexo is in the first place. I also admit this whole thread is solipsistic at best. Thanks @bep and @budparr

If you use Hugo for your notes, you might like: https://github.com/maebert/jrnl

Just read your article @budparr https://www.thenewdynamic.org/article/migrate-from-any-cms-to-markdown/

+1 for your comment that manual migration=clean content

Over the years I’ve tried several scripts while switching platforms. Every single time, I had to intervene manually (with Regex or search and replace) to clean up the content in the end.

So nowadays I also migrate content manually from start to finish.


Thanks, @alexandros - If you have anything to add to the article from your experiences, do let me know.