Creating a Website Using Hugo and Github Pages
Welcome, STEMinist readers! Today, we’ll dive into crafting a website with Hugo (a cool static site generator) and hosting it on GitHub Pages. Let’s get started!
1. Install Hugo
on your computer.
First off, you need to install Hugo on your machine. For PC users, Chocolatey is your best friend, and for macOS, Homebrew has got your back.
|
If you haven’t been introduced to Chocolatey or Homebrew yet, check out the alternative installation methods for Hugo.
2. Pick a Hugo Theme
Hugo has an impressive library of templates. Take a peek, grab something that vibes with you, and snag the code from GitHub as a zip file. For instance, I’m rocking the LoveIt template for this blog.
3.Set Up Your GitHub Repository
Time to create a public GitHub repository for your site. From there, go to ‘Settings’ > ‘Pages’. Enable Pages and under ‘Build and Deployment’, select ‘GitHub Actions’ in the source dropdown.
4. Tidy Up Your Repository
Add a .gitignore file with the following entries:
|
Next up, we’re creating a .github
folder with a workflows
subfolder. Inside workflows
, we’ll need a hugo.yaml
file.
5. Set Up GitHub Pages Workflow
Alright, we’ll populate hugo.yaml
with the following code (as found in Hugo’s guide to deployment), which will get your GitHub Pages workflow in gear:
|
6. Bring In the Hugo Template
Unzip your downloaded Hugo template code into the root folder of your GitHub repository. Your folder structure should look something like this:
├── .github
│ ├── workflows
│ │ ├── hugo.yaml
│ ├── css
│ │ ├── **/*.css
│ ├── images
│ ├── js
│ ├── index.html
├── .gitignore
├── content
├── resources
├── themes
│ ├── [Theme Name]
└── config.toml
Keep in mind that folders like content
, resources
, themes
, and files like config.toml
may vary based on the theme you’ve chosen.
7. Personalize Your Theme
Now, tweak your theme as per its specific documentation. Run hugo serve from your project’s root (where config.toml
resides) to preview your site locally.
8. Commit and Push Changes
Happy with your tweaks? Commit and push ’em to your GitHub repository. Pro tip: run hugo serve
before pushing changes to make sure everything’s copacetic.
9. Verify Deployment
Head over to “Actions” in your GitHub repository. Under “All Workflows”, find the run corresponding to your latest commit. Once complete, its indicator should turn green.
10. Take a Peek at Your Live Website
Click on your latest commit message. Under “deploy”, you’ll find the link to your newly-minted website. Go ahead and check it out!
And there it is! You’ve just built and deployed a website using Hugo and GitHub Pages. Your site will update automatically with each new change that’s pushed. Enjoy your new digital presence and happy coding!