Build a hugo blog and deploy it to Github

premise

  1. Be sure to configure git. For specific tutorials, see Building a hexo blog under windows and deploying it to github

  2. It is recommended to install Windows Terminal in the Microsoft Store to facilitate subsequent operations

image-20210310082338604

Install

  1. Download: Go to the GitHub home page to download https://github.com/gohugoio/hugo/releases

    image-20210310080453206

    After downloading and decompressing, you can get

    image-20210310080916612

  2. Configure environment variables: Add the directory where hugo.exe is located to the system environment variable Path

    Copy the directory where hugo.exe is located above

    image-20210310080947304

    Open and edit system environment variables

    image-20210310081137997

    Select environment variables

    image-20210310081215698

    Click the system variable Path below and select Edit

    image-20210310081345063

    Click New on the right and paste the copied path into it

    image-20210310081725299

    Then click OK all the way to exit

  3. Verification: open a terminal, enter

hugo version

image-20210310081923874

If the version number appears, the installation is successful

start up

  1. Create a blog folder: Create a blog under a folder called tmp

    image-20210310082757147

    Open the terminal and switch to this directory

    image-20210310082836219

    Enter the command to create a blog

hugo new site myblog

image-20210310082903028

The blog has been built, and a directory named myblog is generated under this path

image-20210310083024849

Switch to the myblog directory for follow-up operations

image-20210310083214295

  1. Download the theme https://themes.gohugo.io/, install it according to the theme requirements, and modify config.toml

    Take the m10c theme as an example

    image-20210310083616412

    There are hints at the bottom of the page

    image-20210310083659698

    That is, clone the warehouse in the myblog directory

git clone [email protected]:vaga/hugo-theme-m10c.git themes/m10c

image-20210310083926147

At this time, the m10c theme directory is generated in the myblog/themes directory

image-20210310084054141

Next open the config.toml file in the myblog directory

image-20210310084147742

add a line

image-20210310084236183

  1. start a blog
hugo server --theme=m10c -D

image-20210310084317807

Now the blog is started on port 1313 of this machine, enter in the browser search box localhost:1313to see the generated blog

image-20210310084504979

Press Ctrl + C to terminate the blog

  1. Create an article: enter the command
hugo new post/first.md

image-20210310084739298

At this time, there are newly created articles in myblog/content/postthe directory

image-20210310084807367

open file for editing

image-20210310084928125

Note that the above draftindicates whether the article is a draft, and the default is that truethe draft will not appear on the website

Enter the command again

hugo server --theme=m10c -D

to see the changes

image-20210310085159036

image-20210310085210434

deploy

  1. Create a new warehouse on Githubusername.github.io

    Must be username.github.io, usernamefor your Github username

  2. Use hugo to generate web pages and host them in GitHub warehouse

hugo --theme=m10c --baseUrl="https://wjl-lab.github.io/" -D
  1. myblog/publicPush the directory to the master branch of the newly created warehouse
cd public
git init
git add .
git commit -m "message"
git remote add origin https://github.com/wjl-lab/wjl-lab.github.io.git
git push -u origin master
  1. Visit the website wjl-lab.github.io

add article

hugo new post/xxx.md
hugo --theme=m10c --baseUrl="https://wjl-lab(username).github.io/" -D
cd public
git add .
git commit -m "message"
git push
  • create article

  • Generate pages with hugo

  • push to the remote repository on GitHub

Change setting

Find out by yourself. . .

fix image problems

  1. Images are placed in the static directory
![](/images/images.jpg)
  1. Images are placed in a folder with the same name as the blog file
![](images.jpg)
  1. Use PicGo + Gitee to create a picture bed

For specific tutorials, see picgo-gitee map bed construction

Guess you like

Origin blog.csdn.net/wji15/article/details/126632895