π Saturday, Mar 30, 2024
β° 19:25:10
π Saturday, Mar 30, 2024 19:25:10
π Reading time: 5 min
π·οΈ
I started my Hugo website by selecting the Terminal theme, known for its clean and modern design. However, rather than using the theme directly, I decided to leverage its codebase to create a fully custom site that better suited my needs. Here’s how I did it:
git clone https://github.com/panr/hugo-theme-terminal.git themes/terminal
cp -r themes/terminal/layouts layouts/
cp -r themes/terminal/static static/
cp -r themes/terminal/assets assets/
To ensure everything works perfectly, I often build and preview the site locally - which i recommend doing before pushing:
hugo server -D
-D
flag includes draft content (draft: true
in front matter) in the local build.hugo --log --logFile hugo.log
hugo.log
file that captures all logs, helping to identify and resolve issues like missing partials or incorrect configurations.To deploy the website, I used GitHub Pages. Hereβs the step by step process I followed:
# Sample workflow for building and deploying a Hugo site to GitHub Pages
name: Deploy Hugo site to Pages
on:
# Runs on pushes targeting the default branch
push:
branches:
- main
# Allows you to run this workflow manually from the "Actions" tab
workflow_dispatch:
# Set the permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, DO NOT cancel in-progress runs as you want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
# Default to bash
defaults:
run:
shell: bash
jobs:
# Build job
build:
runs-on: ubuntu-latest
env:
HUGO_VERSION: 0.128.0
steps:
- name: Install Hugo CLI
run: |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb
- name: Install Dart Sass
run: sudo snap install dart-sass
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Install Node.js dependencies
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true"
- name: Build with Hugo
env:
HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache
HUGO_ENVIRONMENT: production
TZ: America/Los_Angeles
run: |
hugo \
--gc \
--minify \
--baseURL "${{ steps.pages.outputs.base_url }}/"
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./public
# The Deployment Job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
To automate the deployments, set up a GitHub Actions workflow. My .github/workflows/deploy.yml
looks like this:
name: Build and Deploy The Hugo Site
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: '0.115.2'
- name: Build
run: hugo
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
Setting the Domain in GitHub Pages:
mycustomdomain.com
.Adding a CNAME File:
CNAME
file to the static
directory with the content:mycustomdomain.com
Domain Verification:
DNS Records Setup:
@
) to the following IP addresses:185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
These IPs are GitHub’s server addresses.
CNAME Record:
For the www
subdomain, I added a CNAME record pointing to username.github.io
, replacing username
with my GitHub username.
baseURL: 'https://website.com/'
languageCode: 'en-us'
title: 'My Site'
timeZone: "America/Los_Angeles"
menus:
main:
- identifier: about
name: About
url: /about
weight: 20
- identifier: blog
name: Blog
url: /blog
weight: 30
- identifier: tags
name: Tags
url: /tags
weight: 40
paginate: 10
permalinks:
blog: "/blog/:year/:month/:day/:title/"
taxonomies:
tag: "tags"
author: "authors"
indexes:
tag: "tags"
markup:
defaultMarkdownHandler: "goldmark"
goldmark:
# Enable or disable smartypants (automatic conversion of ASCII punctuation to smart punctuation)
smartypants: true
# Enable or disable fractions (automatic conversion of fractions)
fractions: true
# Enable or disable superscript and subscript support
# (enable to allow ^ and ~ for superscript and subscript)
superscript: true
unsafe: true
outputs:
section:
- HTML
- RSS
- sitemap-blog.xml
home:
- HTML
- RSS
- sitemap.xml
params:
social:
- name: github
url: https://github.com/myusername
- name: x
url: https://x.com/myusername
- name: youtube
url: https://youtube.com/username
- name: linkedin
url: https://linkedin.com/in/username
module:
hugoVersion:
extended: false
min: "0.116.0"