Beginners question: How to build the site correctly

Hello, friends! I’m confused about building the site with Hugo. Sorry, I’m newbie.

I’m building the site using command: hugo. And then I remove some of my pages, or changing file name of pages within content folder.

Then if I rebuild site with hugo, but my old pages within the public folder still exist? If I remove some page, command hugo don’t remove those pages when I rebuild the site? It’s very strange behavior.

And I should every time remove a manually public folder, and rebuild the site again with hugo command?

Is this a bug or a feature? I can’t figure it out. It looks slow, because first I need remove manually whole public folder, and only then rebuild the site again. Why hugo can’t just rebuild site normally with hugo command?

First of all it’s definitely not slow. Forget that one :slight_smile:

Secondly: hugo has command line parameters. If you wish to delete everything in the public directory (or whatever directory you have configured for the output of your site) then use --cleanDestinationDir. More parameters are found in the documentation. Like here: hugo | Hugo

Why should Hugo delete arbitrarily files that it finds and that have nothing to do with it’s tasks that you lay out in the layouts and config folders? That’s not safe. If you wish to cleanup the destination folder tell hugo so and it will do it.

So yes, feature, not bug.

Thank you very much for the answer!

As I understand, basic hugo command will update content pages, but not remove them, right? And basic hugo command also able to update site config, and data from front matter?

Or maybe better to use just hugo --cleanDestinationDir each time?

Because it’s easy to get confused, for example I remove or change file name of content pages, then if I use basic hugo command, nothing will happen for my actual content pages within public folder. And thats, because I use hugo command without flag --cleanDestinationDir, it’s easy to forget. It’s again strange behavior, really don’t understand that.

Is there possible to replace basic hugo command with hugo --cleanDestinationDir? Maybe it’s more convenient will be for users. And if someone need to save files without removing them, he should to use flag, something like: -saveDestinationDir-, etc.

That depends on your operating system. On Linux, for instance Ubuntu, I can just add an alias to my bash configuration that runs hugo --any-command-i-want when I type hugo, but that really depends on what system you use. It’s not hugo’s task to optimise that for you.

FYI: The --cleanDestinationDir option doesn’t do what you think it does.

https://github.com/gohugoio/hugo/issues/8433#issuecomment-822988001

1 Like

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