|
| 1 | +--- |
| 2 | +title: "An Introduction to Hugo" |
| 3 | +date: "2025-11-29" |
| 4 | +draft: false |
| 5 | +description: "This blog will discuss Hugo and why it's a top static site generator." |
| 6 | +showToc: true |
| 7 | +tags: ["git", "github", "workflows", "hugo"] |
| 8 | +--- |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +## Introduction |
| 13 | +Hugo is a fast and reliable static site generator written in Go. Designed for performance and stability, it can generate even the largest websites in seconds. Furthermore, Hugo is highly customizable, allowing you to tweak configurations and apply themes easily via the `hugo.toml` file. This makes it popular for sites such as blogs, documentation, etc. |
| 14 | + |
| 15 | +In this post, we’ll cover the basics of Hugo and show you how to quickly push and deploy your website using GitHub Workflows within seconds! |
| 16 | + |
| 17 | +## Benefits of Hugo |
| 18 | +Hugo is known widely for its following advantages: |
| 19 | + |
| 20 | +- Super fast |
| 21 | +- Easy to configure |
| 22 | +- Customizable |
| 23 | +- Built-in SEO-friendly features |
| 24 | + |
| 25 | +# Setting up Hugo |
| 26 | +Setting up Hugo is very easy, as shown by the below steps: |
| 27 | + |
| 28 | +### Step 1: Install Hugo |
| 29 | +For Debian-based distributions: |
| 30 | + |
| 31 | +``` |
| 32 | +sudo apt update |
| 33 | +
|
| 34 | +sudo apt install hugo |
| 35 | +``` |
| 36 | + |
| 37 | +For Arch Linux-based distributions: |
| 38 | + |
| 39 | +```sh |
| 40 | +sudo pacman -Sy hugo |
| 41 | +``` |
| 42 | +> Hugo binaries are also availible at: [Hugo's GitHub Releases](https://github.com/gohugoio/hugo/releases) |
| 43 | +
|
| 44 | +### Step 2: Generate a local site |
| 45 | +By running the following command: |
| 46 | + |
| 47 | +```sh |
| 48 | +hugo new site hugo-site |
| 49 | +``` |
| 50 | + |
| 51 | +### Step 3: Initialize Git |
| 52 | +By initializing Git we will be able to add themes as submodules and keep track of our changes. |
| 53 | + |
| 54 | +For more details, check out my blog on [Git and GitHub](/posts/git-and-github). |
| 55 | + |
| 56 | +```sh |
| 57 | +git init |
| 58 | +``` |
| 59 | +### Step 4: Add a theme of your preference |
| 60 | +The best thing about Hugo is that you can choose the way your site looks. |
| 61 | + |
| 62 | +There are a lot of themes available at [Hugo Themes](https://themes.gohugo.io/). |
| 63 | + |
| 64 | +After choosing your theme, add it as a submodule with: |
| 65 | + |
| 66 | +```sh |
| 67 | +git submodule add github-url-to-theme themes/theme-name |
| 68 | +``` |
| 69 | + |
| 70 | +For Example: |
| 71 | + |
| 72 | +We will be using PaperMod for this demo. |
| 73 | + |
| 74 | +```sh |
| 75 | +git submodule add https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod |
| 76 | + |
| 77 | +git commit -m "themes: Add PaperMod" |
| 78 | +``` |
| 79 | + |
| 80 | +### Step 5: Enable your theme |
| 81 | +In your `hugo.toml`: |
| 82 | + |
| 83 | +```toml |
| 84 | +theme = "PaperMod" |
| 85 | +``` |
| 86 | + |
| 87 | +You will now see that upon Hugo regenerating your site, the theme will be applied. |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +Before continuing with our guide, it’s important to understand how Hugo’s file structure works. |
| 92 | +When you run `hugo new site hugo-site`, Hugo generates a folder called `hugo-site` with several subfolders. |
| 93 | + |
| 94 | +### Content |
| 95 | +The `content` folder holds the main content of your site. For example, in a blog site, all your blog posts (in Markdown format) will usually go in `content/posts`. |
| 96 | + |
| 97 | +### Public |
| 98 | +The `public` folder is generated when you run `hugo server` or `hugo`. It contains the fully rendered static website, mostly HTML, CSS, and JS files, ready to be served. You generally do not manually edit this folder. |
| 99 | + |
| 100 | +### Static |
| 101 | +The `static` folder holds files that should be passed to the client as-is, without processing. Hugo copies everything from `static` directly into the root of the `public` folder. For example, a file placed at `static/about/profile.jpg` will be accessible at `https://your-site-url/about/profile.jpg`. |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +### Step 6: Generating a new post |
| 106 | +To generate a new post, run: |
| 107 | + |
| 108 | +```sh |
| 109 | +hugo new posts/first.md |
| 110 | +``` |
| 111 | +This generates a markdown file at content/posts where you add your content. |
| 112 | + |
| 113 | +For example, |
| 114 | + |
| 115 | +```md |
| 116 | +# Hello guys this is my first post! |
| 117 | +``` |
| 118 | + |
| 119 | +### Step 7: Test your changes |
| 120 | +Hugo allows you to run a local server by running the command: |
| 121 | + |
| 122 | +```sh |
| 123 | +hugo server |
| 124 | +``` |
| 125 | + |
| 126 | +This command creates a server that launches an accessible URL, usually `https://localhost:1313`. |
| 127 | + |
| 128 | +Hugo automatically reloads the page when you make changes. |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +# Setting up GitHub Workflows |
| 133 | +Hugo seamlessly integrates with GitHub workflows and allows you to deploy your site for free! |
| 134 | + |
| 135 | +### Step 1: Creating a GitHub repository |
| 136 | +Create a GitHub repository on your account with its name in the following format: |
| 137 | + |
| 138 | +``` |
| 139 | +<yourusername>.github.io |
| 140 | +``` |
| 141 | + |
| 142 | +For example, for my username it would be: |
| 143 | + |
| 144 | +``` |
| 145 | +realahnet.github.io |
| 146 | +``` |
| 147 | +### Step 2: Pushing your changes to the repository |
| 148 | +After staging and committing your changes, push your changes to your GitHub repository. |
| 149 | + |
| 150 | +For more details, check out my blog on [Git and GitHub](/posts/git-and-github). |
| 151 | + |
| 152 | +```sh |
| 153 | +git remote add origin https://github.com/<your-username>/<your-username>.github.io |
| 154 | +``` |
| 155 | + |
| 156 | +For example, for my username it would be: |
| 157 | + |
| 158 | +```sh |
| 159 | +git remote add origin https://github.com/realahnet/realahnet.github.io |
| 160 | +``` |
| 161 | + |
| 162 | +Push your changes to the repository. |
| 163 | +```sh |
| 164 | +git push -u origin master |
| 165 | +``` |
| 166 | + |
| 167 | +### Step 3: Setup GitHub Pages |
| 168 | + |
| 169 | +1. Navigate to the settings tab in your GitHub repository page. |
| 170 | + |
| 171 | +2. Spot the section called "Build and Deployment." |
| 172 | + |
| 173 | +3. Change the source to GitHub Actions as shown in the image below: |
| 174 | + |
| 175 | + |
| 176 | +### Step 4: Setup GitHub Workflow |
| 177 | +GitHub expects a specific directory structure in order to configure your actions. |
| 178 | + |
| 179 | +```.github/workflows``` |
| 180 | + |
| 181 | +It contains a yml file, which specifies all the configuration for how the project builds and deploys. |
| 182 | + |
| 183 | +Luckily for us, Hugo already has a premade actions profile on GitHub. |
| 184 | + |
| 185 | +1. Navigate to the `Actions` tab and click on "New workflow." |
| 186 | + |
| 187 | +2. Search for `hugo` in the search bar. |
| 188 | + |
| 189 | +3. Click on the Hugo workflow that shows up: |
| 190 | + |
| 191 | + |
| 192 | + |
| 193 | +4. Click on configure. Now a yml file will pop up. |
| 194 | + |
| 195 | +5. Look for the env section: |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | +6. Change the version to the latest Hugo version available at [Hugo's GitHub Releases.](https://github.com/gohugoio/hugo/releases) |
| 200 | + |
| 201 | +For Example |
| 202 | + |
| 203 | +```yml |
| 204 | +env: |
| 205 | +HUGO_VERSION: 0.152.2 |
| 206 | +``` |
| 207 | +
|
| 208 | +7. Click on commit changes and choose an appropriate commit message. |
| 209 | +
|
| 210 | +8. After committing, the GitHub action will start running. |
| 211 | +
|
| 212 | +9. Once the deployment is successful, your site will be deployed at: |
| 213 | +
|
| 214 | +``` |
| 215 | +<your-username>.github.io |
| 216 | +``` |
| 217 | + |
| 218 | +> Replace your-username with your username |
| 219 | +
|
| 220 | +### Step 5: Correcting baseURL |
| 221 | +Hugo requires you to set a `baseURL` inside `hugo.toml`. This is basically the URL of your website. |
| 222 | +Just update it at the top. |
| 223 | + |
| 224 | +For Example |
| 225 | + |
| 226 | +```toml |
| 227 | +baseURL = 'https://realahnet.github.io' |
| 228 | +``` |
| 229 | + |
| 230 | +--- |
| 231 | + |
| 232 | +# Summary |
| 233 | +Hugo is the perfect choice for anyone looking forward to building and deploying a fast, simple, and elegant site. With its amazing ability for customization and different variety of themes, it is a favorable choice among developers and students. |
| 234 | + |
| 235 | +--- |
0 commit comments