Practical Home Tech

Website ·

How I built this site

Hugo, GitHub and Cloudflare Pages, step by step, from someone who'd never used any of them.

This guide is for absolute beginners, people like me, and for anyone who likes to go beyond a simple service that does everything for you.

By the end you’ll have what I’ve got: a website where creating a new post is quick and easy, and publishing it is one git push. Your posts are plain files you own, not locked into a blogging platform.

I’m not an expert, and I used Claude (an AI) for a lot of this. I’ll point out where it helped and where it got things wrong. If you want the backstory, it’s in Why I started this site.

What you need

One tip before you start: read Hugo’s Quick start first. I relied too heavily on Claude. I would’ve been just as well following the getting started guide, then using Claude when I got stuck.

Installing Hugo and making the site

sudo dnf install hugo
hugo version
hugo new site practicalhometech

dnf is Fedora’s installer. On Windows or Mac, follow Hugo’s installation page instead. hugo version prints the version you’ve got. Make a note of it, because you’ll need it later (mine was 0.162.1).

Terminal output of hugo new site, suggesting a theme as the next step

Hugo then suggests installing a theme. I didn’t use one, because Claude assumed I wanted to keep the look of my first site and wrote the templates for me. I personally wasn’t bothered, and picking a theme can be a point where I get stuck with too many choices.

If you’re following along, pick a theme from themes.gohugo.io and follow its instructions. I haven’t used one myself, so I can’t recommend a particular theme.

Git and GitHub

Git keeps track of every change you make. GitHub keeps a copy online, and that’s where Cloudflare will build your site from. This was all new to me.

Inside your site folder:

git init -b main
git config user.name "Your Name"
git config user.email "[email protected]"

Your email is recorded in every change you save, so use one you don’t mind people seeing. I used my site address, not my personal one.

Tell Git to ignore the files Hugo builds itself:

printf 'public/\nresources/_gen/\n.hugo_build.lock\n' > .gitignore

Then save your first version:

git add .
git commit -m "First commit"

These are the commands you’ll use every time:

Connecting to GitHub

GitHub needs to know it’s really you. I used an SSH key, which I already had. To check whether you have one:

ls ~/.ssh

If you see a file called id_ed25519.pub, you have one. If you don’t, GitHub’s own guide shows you how to make one. I didn’t need to, so I haven’t covered it here.

Then test the connection:

ssh -T [email protected]

The first time, it asks whether you trust github.com. Check the fingerprint it shows against the one on GitHub’s website before typing yes. Then I got this:

[email protected]: Permission denied (publickey).

I expected that. I hadn’t added my key to GitHub yet, so there was no worry.

Terminal showing the GitHub fingerprint prompt, then Permission denied (publickey)

Add the public half of your key (the .pub file, never the other one) at github.com/settings/keys, under New SSH key:

GitHub’s SSH keys page with the new key added

Run ssh -T [email protected] again. This time it says “You’ve successfully authenticated, but GitHub does not provide shell access.” That means it worked.

Next, create a new repository on GitHub. Make it private, and leave everything else empty: no README and no licence. If GitHub adds any files, your first push gets refused. Then connect your site folder to it and send it up:

git remote add origin [email protected]:YOUR-USERNAME/YOUR-REPO.git
git push -u origin main

The private repository on GitHub after the first push

Cloudflare Pages

In Cloudflare, go to Workers & Pages and click Create. Cloudflare now steers you towards Workers. Pages is behind a small link at the bottom: “Need to use the legacy Pages workflow? Continue to Pages.”

Cloudflare’s create screen, with the link to the legacy Pages workflow at the bottom

I used Pages because Claude wanted me to. I don’t think it was required, and I think I would’ve got the same outcome going through the newer route, but I haven’t tried it.

Choose Import an existing Git repository, connect your GitHub account and pick your repo. Then fill in:

SettingWhat I used
Project nameThis becomes your test address, name.pages.dev. Mine defaulted to my old site’s name, so I changed it.
Framework presetHugo
Build commandhugo --minify
Build output directorypublic

Cloudflare build settings: Hugo preset, hugo –minify and public

Under Environment variables, add HUGO_VERSION with the number hugo version gave you. Without it, Cloudflare can build your site with a different, older Hugo than the one on your computer.

The HUGO_VERSION environment variable set to 0.162.1

Click Save and Deploy. My first build took about 18 seconds, and the site appeared at its .pages.dev address. I didn’t think much of it, if I’m honest.

Moving your domain over

My domain was still pointing at my first site, which was another Pages project, so I had to remove it from there first: old project, Custom domains, then remove the domain. Read the confirmation box before you click. I didn’t. Removing the domain also deleted its DNS record, so my site was offline for a few minutes. I expected that, so I was OK.

Cloudflare DNS page after removing the domain, warning that visitors cannot reach the site

If your domain isn’t attached to anything yet, you can skip that part.

On the new project, go to Custom domains, then Set up a custom domain, and type your domain. Cloudflare shows the DNS record it’s going to add: a CNAME pointing your domain at your .pages.dev address. Click Activate domain.

Cloudflare’s Confirm new DNS record screen: a CNAME for the domain pointing at the pages.dev address

The status went from Initializing to Verifying to Active within a few minutes. I did the same for www, and I have a Cloudflare redirect rule that sends www to the bare domain (there’s a ready-made “Redirect from WWW to root” template).

The custom domain showing as Active

This was straightforward for me because I bought my domain from Cloudflare, so its DNS was already there. If your domain is somewhere else, you’ll need to sort that out first. I haven’t done that, so I can’t walk you through it.

To finish:

How I publish a post now

Creating a new post is simple. Create a Markdown file in content/posts/ (only posts in that folder show up on the homepage), then:

hugo server -D

That gives you a preview at http://localhost:1313. Check it, then press Ctrl+C to stop it. Then:

git status
git add .
git commit -m "New post"
git push

And done. Cloudflare picks up the push, and the post is live about a minute later.

What went wrong

No 404 page. Claude’s templates didn’t include a “page not found” page. Without one, Cloudflare Pages shows your homepage for every address that doesn’t exist, so old links to pages I’d taken down showed my homepage instead. I spotted it on the test site and added one. I never thought I needed to have a 404 page set up.

Decisions made for me. Claude decided I’d use its own templates instead of a theme, and Pages instead of Workers, without really asking. Be explicit with Claude. I was happy to go with its template, but if you want to use a Hugo theme, just say so.

An apostrophe broke my config. I put my site description in hugo.toml inside single quotes, and the apostrophe in “I’m” ended the text early. Hugo wouldn’t build until I switched to double quotes. If your text has an apostrophe in it, put it in double quotes.

What it costs

Cost
Domain (from Cloudflare)$5.30 a year (£3.81 on my bank statement)
HugoFree
GitHub (private repository)Free
Cloudflare PagesFree plan

The domain is the only thing I’ve paid for. (My email runs on iCloud+, which I was already paying for long before the site.)