Suggestion: Allow Hugo Server to Invoke Pre/Post Scripts?

As per my thread here: https://discuss.gohugo.io/t/how-to-do-proxying-during-development/5517 I’ve been doing a bit of theming work recently for the Isso comments system on my blog.

Since, on a live site, the comments are dynamically embedded on the page by a Python app. running on a proxy port, I’ve had to cheat a bit in the development stage by creating dummy hard-coded versions of various dynamically created files in the appropriate places, so that Hugo’s server can find & display them.

Therefore, before pushing my changes to the live site, I need to remove all these dummy files first. At the moment I’m doing it like so when building the site:

hugo && rm -r public/isso

Although this is no biggy at the moment, this kind of thing could get a bit unwieldy if there was more of this kind of ‘housework’ to do, before uploading… or if trying to remember similar cleanup operations between various site projects and dev environments. Hence this suggestion:

How’s about adding a config option which would tell Hugo Server to run a shell script either pre- or post- building the site?

That way people could keep this housekeeping script inside the project folder and have it automatically 'do stuff’f© when the site is built, without having to remember to move/delete/whatever any files or folders that shouldn’t be there.

1 Like

What would the benefit be to having hugo run the shell script instead of external tools?

What would the benefits be over:

  • Using make to run pre/post scripts, and then run hugo
  • Using a shell script for custom tasks, and then run hugo

I use make to run several scripts to generate CSS, resize images, and minify code. Using make offers me flexibility that I don’t see available if hugo were running the scripts itself.

Edit:
I think there could be some benefit to hugo running a pre/post shell script. There could be a need for a theme to run some custom logic; such as image resizing, or html post-processing to generate stuff like AMP pages.

Having hugo run the script would make it easier on a user who just downloaded the theme and doesn’t want to work too hard.

Long discussion about exec security in Issue 796. There’s work to do before we allow hugo to execute arbitrary commands.

2 Likes

Whoops! –Bit of crossed wires here, I reckon.

I wasn’t advocating Hugo be given sudo priveleges. I was thinking more of the ability to automatically run a couple of simple ‘clean-up’ commands inside the project directory, after Hugo does a site build, to [re]move folders/files that were needed during development, but which you don’t want uploaded. That kind of thing.

Well, “automatically run … commands” is exactly the issue. It has nothing to do with sudo (other than the fact that sudo is one such command!). It doesn’t matter how many, their location, or how innocuous they may think they are. In the end, hugo will be the one to execute these commands. Hence, the discussion about security in the issue linked above.

1 Like

Why not use a shell script with:

  • Pre-script(s)
  • Hugo command(s)
  • Post-script(s)

Scripts can vary a lot and error handling, results and tests wouldn’t have the same flexibility if they would be handled by hugo.