
If you’re working with Hugo and want to turn your content into static HTML files ready for deployment, you’re in the right place! In this guide, we’ll walk you through the process of generating static HTML pages and deploying them to the web.
Step 1: Building Your Site to Generate HTML Files
Before you can deploy your site, you first need to build it and generate the static HTML files that Hugo uses for deployment.
1.1 Open PowerShell
Open PowerShell on your system if it’s not already open. To do so, press Win + X
and select Windows PowerShell (Admin). Then, navigate to your Hugo project folder where you created the website. For example:
cd C:\Users\YourUsername\Hugo\mywebsite
(Replace YourUsername
with your actual Windows username.)
1.2 Run the Hugo Build Command
In PowerShell, run the following command to generate the HTML files for your site:
hugo
Hugo will build the entire site and output all static files into a folder called public/
.
Step 2: Locating the Generated HTML Files
After the build process completes, all your static HTML pages will be stored in the public/
folder. This folder contains the HTML files for every page of your website.
2.1 Finding the public/
Folder
Navigate to the public/
folder inside your Hugo project directory. For example:
C:\Users\YourUsername\Hugo\mywebsite\public
2.2 Accessing Your Post’s HTML File
Inside the public/
folder, you’ll see HTML files corresponding to your content. For instance, if you have a post called my-first-post.md
, its HTML version will be located at:
public/posts/my-first-post/index.html
Step 3: Previewing Your HTML Locally
Once the HTML files are generated, you can open them in your web browser to preview your site.
3.1 Open the HTML File Locally
- Navigate to the
public/
folder. - Inside the folder for your post (e.g.,
public/posts/my-first-post/
), you’ll find theindex.html
file. - Double-click on the
index.html
file to open it in your default browser.
This will show the static HTML version of your post as it would appear on a live site.
Step 4: Deploying the HTML Pages
Once you have the HTML files, you’re ready to deploy your site! You can upload the contents of the public/
folder to any hosting provider or service.
4.1 Deploying to GitHub Pages
One of the easiest ways to deploy your Hugo site is by using GitHub Pages.
- Follow this official Hugo GitHub Pages Deployment Guide to deploy your site.
4.2 Deploying to Netlify
Netlify is another great hosting option for Hugo sites. It offers continuous deployment and a very simple drag-and-drop method to deploy your static site.
To deploy with Netlify:
- Go to Netlify.
- Drag and drop the
public/
folder into the Netlify dashboard to deploy your site instantly.
4.3 Deploying to Any Web Hosting
If you prefer to use traditional web hosting (like cPanel or FTP):
- Log in to your hosting provider’s file manager (such as cPanel).
- Upload the contents of the
public/
folder to the root of your domain’s web directory. - Your site will be live at the domain URL!
Final Thoughts
Once your site is deployed, anyone can visit your website online. Whether you’re using GitHub Pages, Netlify, or any other web hosting provider, Hugo makes it simple to generate and deploy static sites.
Key Takeaways:
- Build your site using
hugo
to generate HTML files in thepublic/
folder. - Preview your site by opening the
index.html
file locally in your browser. - Deploy the
public/
folder to any hosting provider to take your site live.
With these steps, you now have a static website ready to share with the world. 🚀 If you have any questions about Hugo or the deployment process, feel free to ask!