One thing that bothered me somewhat about the way ox-hugo handles straggler files is that if I ever removed, renamed or otherwise messed with the structure that already existed, it wouldn't handle the redundant files for me.
E.g. if I deleted a post in my org-mode file (from which this website is generated), ox-hugo would happily leave it hanging in my \`content/\` directory, damning me to eternal suffering.
However, using this simple elisp, I can easily delete the content directory, and rebuild it from scratch to ensure that my website is _always_ up to date.
I have yet to put it into a function, or do anything. `C-c C-c` works just fine for me, as it's sitting at the top of the file in a \`:noexport:\` block.
Another issue I solved was that the git `post-receive` hook wouldn't run properly. It took me a short bit but eventually I found that I need to run it in a subshell, and unset the \`GIT_\` env variables to ensure that git doesn't get confused about where to pull the updates from.
```sh
#!/bin/bash
# Directory on the server where the website will be mapped.
export GIT_WORK_TREE=/srv/bajsicki.com/
cd $GIT_WORK_TREE
echo "post-receive: Generating https://bajsicki.com with Hugo in $(pwd)"
# Remove any files already in the public directory, a fresh copy will be generated by hugo
echo "post-receive: Cleaning the /public and /content directory to ensure we're in line."
rm -rf public/ && echo "removing /public in $(pwd)"
rm -rf content/ && echo "removing /content in $(pwd)"
# Update the modules in case of changes and pull the new pages
echo "post-receive: pulling git repo and submodules in $(pwd) w/ subshell"
(
unset $(env | sed -ne 's/^\(GIT_.*\)=.*/\1/p')
cd /srv/bajsicki.com
git pull origin main --recurse-submodules --force
)
# Generate the site with hugo
echo "post-receive: running hugo in $(pwd)"
hugo
# Fix any permission problems.
echo "post-receive: fixing permissions in $(pwd)"
find public -type f -print | xargs -d '\n' chmod 644
find public -type d -print | xargs -d '\n' chmod 755
echo "post-receive: Hugo site deployment in $(pwd) complete"
```
This is my current `post-receive` hook, and it works quite well, I think.
Anyway. Things are working, jankily yet so.
Next: I am praying that I find some time/ brainpower to fix up the CSS on this website. The misaligned sidenotes are quite irritating.
<spanclass="underline">[Join the FSF.](https://my.fsf.org/join)</span>