How to run command while rebuilding automatically?

I’m hosting my site on the local server. I wrote a python file to generate cross-reference data into a JSON file that is used to generate pages. Thus I’m looking for a method to run this python script every time before the site is rebuilt when some changes are made.

How about just using a shell script? Psuedo-code:

#!/bin/bash
python myfile.py
hugo
# add any desired switches to hugo;
# here, it's just bare-bones

Save that to, say, pyhugo.sh, then run:

./pyhugo.sh
2 Likes

Yes, this is how I deploy my site, but I’d like a way to run this script automatically when it’s rebuilt on the local server.

I think the best way is to run the script whenever a file changes, you can try with while in your terminal, check an example: while command in Linux with example - GeeksforGeeks

Hmm… it seems not easy. I was going to ascertain if hugo provides a way to do this work, for example, a hook. For now, I think your method is the best. I would mark it as the solution.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.