Why is there a "public" folder?

I have been putting static resources like favicons in the static folder. While I develop my site, I’ve been running hugo server -D, so the site is constantly regenerated as I make changes. At some point while I was messing with my site, a public folder appeared, containing my css, the images, and a new sitemap.xml which I haven’t seen before.

Where did the public folder come from, why is it there / what purpose does it serve, and is there documentation for it? I see the URL management page mentions the public folder as the default target directory for my built website. This confuses me, because I was building and viewing my site for some time without a public directory appearing at all. If this is the normal target directory, how was I seeing a website before the public folder appeared? What triggered its appearance? Why are the images from the static folder duplicated? Can I safely delete the images from the static folder?

If it matters, here’s a git repo with my site as it was the last time I pushed my code, before the public folder appeared.

At one point you’ll have run hugo without specifying server.

public is the folder that contains the files you can upload to a web server for your live website.

1 Like

Feel free to delete that folder, and/or to put it in your .gitignore file.

1 Like

Check the hugo command here. This would explain it.

1 Like

Thank you folks, those are very helpful explanations. I think I was confused by there not being any HTML files in the public folder, but that must be because all of my Markdown files still have “draft: true” in the front matter, so they aren’t getting published.

1 Like

If this were your website, would you put the public folder in .gitignore? This would imply pulling the git repo on the server, and then running Hugo on the server to generate the files.

Or would you include the public folder in the repo? To me that implies that we run Hugo either locally or on the server, and then push the results to the git repo.

It depends on how you’re planning to serve the content. If you’re going to use a service like netlify, which builds the site from source, then you don’t need to include the /public folder. However, if you’re going to serve it straight from your repository (and I think GitHub pages works that way…and your server may too) then, you should push /public to the repository.


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