Ultimate guide to build your own blog

Build Your Hugo Blog Using GitHub and Netlify

Contents

All hugo commands should be run in the root level


For Mac user:

1
2
brew install hugo
brew install git
1
2
hugo new site myblog
cd myblog

You can find Hugo themes Here

In this case I use LoveIt theme as my example

1
2
git init
git submodule add https://github.com/dillonzq/LoveIt.git themes/LoveIt

Copy config.toml content from example site to your config.toml

You can make your own changes in config.toml file

Step 5: Create your first post

1
hugo new posts/my-first-post.md

In .md file, set:

1
draft: false

Command above will generate a my-first-post.md file under the path: ./content/posts

You should always use hugo new posts/file.md to create new files

1
hugo serve

Go to http://localhost:1313

Run:

1
hugo

After you run the hugo command above, you will see content created under public folder in your blog folder


If you want to deploy on GitHub page:

Create a repo named your-github-username.github.io

For example:

My GitHub username is code-panda-x My repo will be named code-panda-x.github.io

1
2
3
4
5
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/your-github-username/your-repo-name.git
git push -u origin main

Run :

1
hugo

Above code will update corresponding changes to public folder

Then run:

1
2
3
$ git add .
$ git commit -m "add blog post"
$ git push

You can use git status to check your changes

1
$ git status

Add netlify.toml file to your blog:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[build]
publish = "public"
command = "hugo --gc --minify"

[context.production.environment]
HUGO_VERSION = "0.93.0"
HUGO_ENV = "production"
HUGO_ENABLEGITINFO = "true"

[context.split1]
command = "hugo --gc --minify --enableGitInfo"

[context.split1.environment]
HUGO_VERSION = "0.93.0"
HUGO_ENV = "production"

[context.deploy-preview]
command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"

[context.deploy-preview.environment]
HUGO_VERSION = "0.93.0"

[context.branch-deploy]
command = "hugo --gc --minify -b $DEPLOY_PRIME_URL"

[context.branch-deploy.environment]
HUGO_VERSION = "0.93.0"

[context.next.environment]
HUGO_ENABLEGITINFO = "true"

[[redirects]]
from = "/npmjs/*"
to = "/npmjs/"
status = 200
  1. Sign in Netlify with GitHub account
  2. Add new site - Import an existing project
  3. Select your GitHub repo
  4. Your site will be pubished with a netlify domain
  1. Purchase your domain at Godaddy.com or namecheap.com
  2. Netlify Configuration Domains - Custom domains - Add custom domain - Enter your purchased domain

Add:

  1. Type: A Name: @ Value: 75.2.60.5 (Netlify’s load balancer IP address)
  2. Type: CNAME Name: www Value: your-url.netlify.app

Your site will be published on your-github-username.github.io

  1. Purchase your domain at Godaddy.com or namecheap.com
  2. GitHub Page Configuration Settings - Code and automation - Custom domain - Enter your purchased domain

Add:

  1. Type: A Name: @ Value: 185.199.108.153
  2. Type: CNAME Name: www Value: your-github-username.github.io

1
    Building sites … ERROR 2019/11/30 09:22:03 Failed to read Git log: fatal: your current branch 'master' does not have any commits yet Built in 135 ms

In config.toml:

Set enableGitInfo = true


1
Error: module "xxx" not found; either add it as a Hugo Module or store it in "/home".: module does not exist

In config.toml:

Set themesDir = "themes"

No comment yet.
Powered By Valine
v1.4.14