GitHub Pages Hugo: A Step-by-Step Website Creation Guide

Author

Reads 725

Close-up of a hand holding a 'Fork me on GitHub' sticker, blurred background.
Credit: pexels.com, Close-up of a hand holding a 'Fork me on GitHub' sticker, blurred background.

Creating a website with GitHub Pages and Hugo is a straightforward process that requires minimal technical expertise.

Hugo is a static site generator that allows you to build fast, secure, and scalable websites.

To get started, you'll need to install Hugo on your computer, which can be done via the official Hugo download page.

After installing Hugo, you can create a new Hugo site using the command `hugo new site mywebsite`.

Prerequisites

To get started with GitHub Pages and Hugo, you'll need a few things in place.

First and foremost, you'll need a GitHub account. This will be your home base for hosting your site and managing your code.

Next, you'll need to have Hugo installed on your system. This is the static site generator that will help you build your site.

In addition to these two, it's also helpful to have a basic familiarity with Git and GitHub Pages. This will make it easier to understand how to use the tools and features of GitHub Pages with Hugo.

Setting Up

Credit: youtube.com, Creating a Blog with Hugo and Github in 10 minutes

To set up GitHub Pages with Hugo, start by navigating to your GitHub repository's Settings page and selecting Pages under Build and Deployment. Update the source from Deploy from a branch to GitHub Action.

Create a new folder called .github/workflows in your local repository and add a hugo.yaml file with the following contents. This will trigger the workflow automatically upon your next push to the main branch.

You can see the workflow by navigating to Actions, as shown in the screenshot below. This will give you an overview of the process and ensure it's working correctly.

To publish your site to GitHub Pages, you need to set up a workflow for GitHub Actions. This involves creating a new folder called .github/workflows and adding a hugo.yaml file with the necessary contents.

Navigate to Settings > Pages again and add your custom domain under the custom domain field. GitHub will create a file called CNAME containing the custom domain and commit it to your repository.

For the A record, set the following values: 185.199.108.153185.199.109.153185.199.110.153185.199.111.153

For the CNAME, set the value to username.github.io. This will update the DNS records for your domain and ensure your site is accessible at your custom domain.

Credit: youtube.com, How to set-up a static Hugo website on GitHub Pages in 2 minutes

To set up your custom domain, you need to manage the DNS records for your domain. This involves updating the A and CNAME records with the specified values.

Once you've set up your custom domain, you might need to wait for up to 24 hours to see the site on your custom domain. This is because DNS changes can take some time to propagate.

Creating Content

Creating content for your GitHub Pages Hugo site is a breeze. You'll be writing in Markdown, which is incredibly simple and will probably revolutionize how you write stuff.

You can create a new blog post in your content folder, within a subfolder called posts, using the code `hugo new posts/example.md`. This will add an `example.md` file in the content folder.

To create a new post, you can open this file with your editor and start writing away! Use the provided template and commands to streamline the process.

Take a look at this: Hugo Static Website Generator

Credit: youtube.com, Hugo in 100 Seconds

Each post/page you make will begin with some canned content called the “header”. This provides some parameters to control your posts/pages, and it will look something like this: `Creating a new webpage is just as simple`.

To add new content, you can use the `hugo new` command followed by the path and file name you want to create. For example, `hugo new posts/example.md` added an `example.md` file in the content folder.

Once you're done with the changes to your post, you can change `draft: true` to `draft: false` to have it deployed. This is depending on the theme you are using. If you're using the default theme, then Hugo does not publish draft content when you build the site.

Customizing

Customizing your GitHub Pages Hugo site is a breeze. You can tailor your website by adjusting settings in the config.yml file located in the root folder.

The first things you probably want to change are the baseURL, title, and theme.

Deploying

Credit: youtube.com, Deploy Hugo Blog to Github Pages via Github Actions w/ a Custom Domain

Deploying your Hugo website to GitHub Pages is a straightforward process. First, clone your repository to your computer with the command `git clone [email protected]:magsther/magsther.github.io.git`.

Once you have cloned your repository, navigate to the folder and run `hugo new site ollycloud -f yml` to create a new Hugo site. After that, follow the additional steps provided to complete the deployment process.

To automate the process of rebuilding and deploying your website, you can use GitHub Actions. This will rebuild your site and deploy the changes whenever you push a change from your local repository.

Here's a step-by-step guide to deploying your Hugo website to GitHub Pages using GitHub Actions:

1. Change the deploy from the branch to GitHub Actions in your GitHub repository settings.

2. Create a folder `.github` and inside it, create another folder named `workflows`.

3. Create a `hugo.yaml` file inside the `workflows` folder and copy the following code into it.

Credit: youtube.com, Hugo Static Site Generator - Quick start, with GitHub Pages and GitHub Actions

4. Commit the change to your local repository with a commit message like "Add workflow" and push to GitHub.

5. From the GitHub repository, choose Actions to see the workflow in action.

After pushing any changes to your main branch, go to the "Actions" tab in your GitHub repo to see the workflow in action. If it completes without errors, your site should be published to GitHub Pages.

Publishing

Publishing your blog on GitHub Pages is a straightforward process. You can generate the blog using Hugo and then push the changes to GitHub.

To do this, you'll need to run Hugo to generate the blog, which will create a docs folder that you'll need to add an entry for in the config.yml file.

To enable GitHub Pages, go to your GitHub repository and click on Pages. From there, change the Source from None to Deploy from a branch.

Save your changes, and after a short while, you'll see that your blog is now published at https://username.github.io.

Here's an interesting read: Blog Page Web Design

Woman in focus working on software development remotely on laptop indoors.
Credit: pexels.com, Woman in focus working on software development remotely on laptop indoors.

Here's a step-by-step guide to get you started:

  1. Create a new post with hugo new posts/example2.md
  2. Build the site with hugo
  3. Add, commit and push the changes to GitHub with git add . && git commit -m 'creating my second post' -a && git push
  4. Watch the workflow in GitHub Actions
  5. New posts are published at https://username.github.io

Managing

Managing your GitHub Pages Hugo site is a breeze. You can add new posts by creating a new file with Hugo's command `hugo new posts/example2.md`.

To publish your new posts, you'll need to build the site with Hugo. This will generate the static files that will be hosted on GitHub Pages.

To update your site on GitHub, you'll need to add, commit, and push the changes. This can be done with a single command: `git add . && git commit -m 'creating my second post' -a && git push`.

Once you've pushed the changes, you can watch the workflow in GitHub Actions to see the build process in action.

Your new posts will be published at `https://username.github.io`.

Domain and Hosting

To set up a custom domain on GitHub Pages, navigate to Settings > Pages and add your domain under the custom domain field. GitHub will create a file called CNAME containing the custom domain and commit it to your repository.

You'll need to manage the DNS records for your domain, which will vary depending on your domain provider. For the A record, set the following values: 185.199.108.153185.199.109.153185.199.110.153185.199.111.153

For the CNAME, set the value to username.github.io. This will integrate your domain into your GitHub account. Note that DNS propagation may take up to 24 hours to complete.

Once you've set up your custom domain, you can tailor your website further by adjusting settings in the config.yml file located in the root folder. The first things you probably want to change are the baseURL, title, and the theme.

Workflow

Credit: youtube.com, How Do I Use Hugo With GitHub Pages? - Next LVL Programming

To set up a workflow for your GitHub Pages Hugo site, you'll need to create a GitHub Actions workflow. Create a folder named .github and inside it another folder named workflows.

Copy and paste the GitHub Actions YAML configuration from Hugo's website into a new YAML file, for example, hugo.yml. Make sure to adjust the HUGO_VERSION environment variable to match your Hugo version.

Add the .github folder to your Git repository and push it to GitHub.

Verify Deployment

Verify Deployment is an essential step in setting up your GitHub Pages Hugo site.

After making any changes to your site, push them to your main branch.

Go to the "Actions" tab in your GitHub repository to see your workflow in action.

If the workflow completes without errors, your site should be published to GitHub Pages.

Margarita Champlin

Writer

Margarita Champlin is a seasoned writer with a passion for crafting informative and engaging content. With a keen eye for detail and a knack for simplifying complex topics, she has established herself as a go-to expert in the field of technology. Her writing has been featured in various publications, covering a range of topics, including Azure Monitoring.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.