A better way to clean Hugo's public directory

I had previously mentioned the script I use to build and deploy my Hugo website. Among other things, it checked if a public folder existed in a determined path and proceeded to delete it with rm -rf.

That works fine and it’s not much of a hassle but I just found out that Hugo already has an option that does that. The option in question is cleanDestinationDir and can either be used as a flag in conjunction with the hugo command or added to the website’s config file. I am going with the latter.

When building a website with this flag, all public files will be deleted, but static and hidden folders will remain intact. This is especially useful if the public directory is also a Git repository. Additionally, licenses, readmes and other such files should be added to the static folder to avoid deletion.