跳到主要内容
hugo安装
博客 hugo

hugo安装

3269 字 18 分钟 -- 阅读 -- 评论
最后更新于:

hugo安装

实验环境

1win10
2git version 2.17.0.windows.1
3hugo v0.98.0

实验软件

链接:https://pan.baidu.com/s/1C-2E0-6Ub7s9DG6npUoZ8Q?pwd=elmi 提取码:elmi 2022.5.4-hugo实验软件

image-20220504164655658
图片1

前置条件

如果你想拥有一个心可以栖息的地方,那么就来和我一起搭建一个属于自己的博客平台,在这里,你可以随心所欲!

1.安装git

见我的另一篇文章:https://blog.csdn.net/weixin_39246554/article/details/124569192?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22124569192%22%2C%22source%22%3A%22weixin_39246554%22%7D&ctrtid=mr1mD

image-20220504130251037
图片2

image-20220504130334477
图片3

2.安装hugo

  • 打开hugo下载链接,直接下载go二进制安装包:

https://github.com/gohugoio/hugo/releases/download/v0.98.0/hugo_extended_0.98.0_Windows-64bit.zip

image-20220503221850842
图片4

  • 将下载的go二进制安装包放到自己电脑某个目录下,然后将其路径放到自己电脑的环境变量下

将下载好的二进制安装包,放到自己pc某个目录下:(自己配置目录为D:\SoftInstall\hugo)

image-20220503222615738
图片5

配置环境变量具体步骤如下:

win + R,输入:sysdm.cpl快速打开pc的环境变量配置:

点击高级:

image-20220503222139220
图片6

点击环境变量:

image-20220503222155266
图片7

来到系统变量,找到Path那一行,点击编辑:

image-20220503222235120
图片8

点击新建,然后输入刚才下载的二进制目录所在路径,点击确认:

image-20220503222350485
图片9

点击确认:

image-20220503222447185
图片10

点击确认:

image-20220503222505558
图片11

至此,hugo的环境变量就配置好了,我们打开cmd,输入hugo version查看是否有效果:

image-20220503222838424
图片12

有结果输出,表示hugo安装正常。

3.本地预览

1.创建本地站点根目录

自己来到D:\目录下,然后输入如下命令,进行创建本地站点根目录:

 1$ hugo new site hugoblog
 2Congratulations! Your new Hugo site is created in D:\hugoblog.
 3
 4Just a few more steps and you're ready to go:
 5
 61. Download a theme into the same-named folder.
 7   Choose a theme from https://themes.gohugo.io/ or
 8   create your own with the "hugo new theme <THEMENAME>" command.
 92. Perhaps you want to add some content. You can add single files
10   with "hugo new <SECTIONNAME>\<FILENAME>.<FORMAT>".
113. Start the built-in live server via "hugo server".
12
13Visit https://gohugo.io/ for quickstart guide and full documentation.
14
15
16hg@LAPTOP-G8TUFE0T MINGW64 /d
17$ cd hugoblog/
18
19hg@LAPTOP-G8TUFE0T MINGW64 /d/hugoblog
20$ ls
21archetypes/  config.toml  content/  data/  layouts/  public/  static/  themes/
22
23hg@LAPTOP-G8TUFE0T MINGW64 /d/hugoblog

image-20220503223456852
图片13

2.下载hugo主题

⚠️ 因为hugo没有内置主题,所以你需要去下载一个:

 1hg@LAPTOP-G8TUFE0T MINGW64 /d/hugoblog
 2$ git clone https://github.com/reuixiy/hugo-theme-meme.git themes/meme
 3Cloning into 'themes/meme'...
 4remote: Enumerating objects: 5583, done.
 5remote: Counting objects: 100% (740/740), done.
 6remote: Compressing objects: 100% (289/289), done.
 7remote: Total 5583 (delta 507), reused 451 (delta 451), pack-reused 4843
 8Receiving objects: 100% (5583/5583), 9.31 MiB | 12.59 MiB/s, done.
 9Resolving deltas: 100% (3086/3086), done.
10
11hg@LAPTOP-G8TUFE0T MINGW64 /d/hugoblog
12$ rm config.toml && cp themes/meme/config-examples/en/config.toml config.toml

image-20220503223746534
图片14

3.创建第一个测试文件

1hg@LAPTOP-G8TUFE0T MINGW64 /d/hugoblog
2$ hugo new post/first.md
3Content "D:\\hugoblog\\content\\post\\first.md" created
4
5hg@LAPTOP-G8TUFE0T MINGW64 /d/hugoblog
6$ echo "i love you,xyy hurt!" >> content/post/first.md

image-20220503224628978
图片15

🍀 说明

 1hugo new [路径]文章名.md
 2hugo new会创建包含默认元数据的文章,如果没有路径, 文章会保存在content目录中。
 3
 4md的文章会在开始部分添加元数据,
 5数据格式为 yaml toml json格式如下:
 6
 7+++
 8title = "my first blog"
 9date = "2019-10-28T09:38:35+08:00"
10draft = true
11+++
12
13markdownz正文部分>>>
14PS:
15draft=true表示文章默认为草稿
16draft=false 才能识别非草稿

image-20220504152643077
图片16

4.本地预览

1$ hugo server -v -D
2
3#hugo -d 目标路径
4不指定目标路径, 会默认在public目录下生成可部署的网站.
5我们通过hugo server -D本地生成网站预览. 他会监控页面的更改, 并刷新页面.

image-20220503224411807
图片17

在浏览器打开如下链接,http://localhost:1313/ 观察效果:

image-20220503224734125
图片18

完美。😘

4.将本地数据推送到github仓库并设置公网可访问

1.github上创建仓库

登录github:https://github.com/

点击Your repositories:

image-20220503225108331
图片19

点击new:

image-20220503225154016
图片20

填写仓库名,选择Public,添加一个Readme文件:

image-20220503225218903
图片21

点击Create respository:

image-20220503225328250
图片22

完成仓库创建。

2.将本地文件推送到远程仓库

  • 此时,来到博客根目录,先执行下hugo -D生成下网站所需数据:
1$ hugo -D

image-20220503225746180
图片23

此时,你能看到public目录下,生成可很多文件,这个就是后续生成网站所需要的数据。

  • 此时,来到public目录下,执行如下命令
1$ cd public/
2
3$ git init
4$ git remote add origin git@github.com:OnlyOnexl/hugoblog.git
5$ git add .
6$ git commit -m"first commit"
7$ git push  --set-upstream origin master
8$ gs

image-20220503230328157
图片24

🍀 关于这里如何配置git客户端到github的公私钥方法,请看如下方法:

Git配置ssh登录GitHub管理自己的代码

检测本地pc是否已存在ssh秘钥(不存在可忽略次步骤)

image-20220410072325298
图片25

1️⃣ 设置签名

右键单击鼠标,点击 Git Bash Here输入以下命令,设置签名:

1git config --global user.name  "hg"
2git config --global user.email  "2675263825@qq.com"

2️⃣ 生成ssh秘钥

然后生成密钥(公钥和私钥):

1ssh-keygen -t rsa -C "2675263825@qq.com"
2
3#备注:
41.过程中按2次回车就好;
52.也可以添加-b选项 # ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

image-2021.05.16082430526
图片26

3️⃣ 复制ssh公钥到github

现在密钥已经生成,一般存放在(/c/Users/you/.ssh/id_rsa.pub.),我们运行下面的命令将密钥复制为粘贴板,等会儿会粘贴到github上去:

image-2021.05.16082602732
图片27

image-2021.05.16082634238
图片28

复制 id_rsa.pub 文件内容,登录 GitHub,点击用户头像→Settings→SSH and GPG keys,New SSH Key,输入复制的密钥信息,保存:

图片29
图片30
图片31
图片32
图片33
图片34
图片35
图片36
图片37
图片38
图片39
图片40
图片41
图片42
图片43
图片44
图片45
图片46
图片47
图片48
图片49
图片50
图片51
图片52
图片53
图片54
图片55
图片56
图片57
image-20221007201649923
图片58
图片59
图片60
图片61
图片62
图片63
图片64
图片65
图片66
图片67
图片68
图片69
图片70
图片71
图片72
图片73
图片74
图片75
图片76
图片77
图片78
图片79
图片80
图片81
图片82
图片83
图片84
图片85
图片86
图片87
图片88
图片89
图片90
图片91
图片92
图片93
图片94
图片95
图片96
图片97
图片98
图片99
图片100
图片101
图片102
图片103
图片104
图片105
图片106
图片107
图片108
图片109
图片110
图片111

image-20210311224743448
图片112

4️⃣ 验证:本地连接Github

右键单击鼠标,点击 Git Bash Here输入以下命令,如果如下图所示,出现你的用户名,那就成功了

1$ ssh -T git@github.com

image-2021.05.16083311660
图片113

  • 此时来到github仓库下,观看数据已经被推送上来了:

image-20220503230406483
图片114

  • 最后记得在github上设置下gitpages功能

点击Settings,Pages:

image-20220503230504717
图片115

选择master分支,点击Save:

image-20220504134929579
图片116

  • 验证效果:

公网访问:

https://onlyonexl.github.io/hugoblog/

image-20220504134958504
图片117

这里应该是网络问题!

5.如何自定义域名

  • 购买域名

到阿里云万网,购买域名:

https://www.aliyun.com/ss/?spm=5176.19720258.J_8058803260.36.e9392c4aBhlzKl&k=%E5%9F%9F%E5%90%8D

image-20220504145926766
图片118

域名购买后记得实名认证下:(用阿里云手机app效果会更好!)

  • 配置域名解析

来到阿里云域名控制台,配置域名解析:

image-20220504135334574
图片119

  • 配置GitHub Pages

image-20220503230735556
图片120

image-20220504150202558
图片121

  • 验证

公网访问域名:http://www.onlyyou520.com/

image-20220504135828852
图片122

大功告成,接下来就可以开心写自己博客了!😘

最新文章

文档导航