GitHub Pages serves content from the docs
directory in your repository. By default, Hugo generates content in a public
directory. To make GitHub Pages work with Hugo, you need to configure Hugo to generate content into the docs directory instead.
Open your config.toml
file and add the following line:
publishDir = "docs"
After making the changes in the config.toml
file, rebuild your site with Hugo:
hugo
This will update the docs directory with the necessary static files.
Commit the changes made to your repository, including the generated static files in the docs
directory.
Go to your GitHub repository’s Settings tab. Scroll down to the GitHub Pages section. In the ‘Source’ dropdown, select the master
branch /docs
folder option. This tells GitHub Pages to serve your site from the docs folder in the master branch.
Click on the ‘Save’ button to apply the changes. GitHub Pages should now be enabled for your repository. You’ll see a green box indicating the URL where your site is published.
After a few moments, your Hugo site should be live on GitHub Pages. You can access it using the URL shown in the GitHub Pages section of your repository’s Settings.
Whenever you want to update your site, follow these steps:
hugo
command.The changes will automatically be reflected on your live site hosted by GitHub Pages.