github-hugo搭建博客
下载并解压文件夹,添加路径到path。
1 下载hugo
Releases · gohugoio/hugo (github.com)
下载并解压文件夹,添加路径到path
2 创建本地博客文件夹
hugo new site blog
3 配置even主题
在blog根目录下执行
git clone https://github.com/olOwOlo/hugo-theme-even themes/even
使用even主题自带的全局配置config.toml覆盖Hugo初始安装的config.toml
cp themes/even/exampleSite/config.toml ./
根据个人需要,修改blog/config.toml里的配置项,比如网站首页title,右上角菜单名称,底部链接名称等。
注意:highlightInClient配置项和pygments开头的配置项不能都启用,都启用会导致markdown里插入代码块的时候样式错误。highlightInClient使用默认的false即可,不用修改。
使用even主题自带的博客文章默认配置themes/even/archetypes/default.md
覆盖Hugo初始安装的archetypes/default.md
cp themes/even/archetypes/default.md ./archetypes/
修改archetypes/default.md
里的默认配置项,把comment和toc都设置为true,用于开启文章评论功能和文章自动生成目录功能。
启动本地Hugo server,查看博客效果,本地地址:http://localhost:1313/
hugo server -D
4 写文章 本地查看
在blog根目录
hugo new post/test.md
发布:在blog根目录执行hugo
命令或者hugo -t even
命令,自动根据md文件生成文章的静态页面,静态页面发布在根目录的public文件夹下面
hugo
启动Hugo server,查看效果(-D表示草稿也渲染)
hugo server -D
删除文章中的draft: true
或改为false,这样才能真正发布,查看效果
hugo server
5 使用GitHub Pages发布到互联网
-
创建repo,命名 username.github.io,username是GitHub的用户名
-
把本地博客public目录下的内容push到GitHub仓库
-
方法一(不推荐)
cd publicgit initgit remote add origin git@github.com:TheChlio/TheChlio.github.io.git git statusgit add .git commit -m 'blog first commit'git push origin master
push时遇到的问题:
解决:查看C:/user/.ssh文件夹下有无id_rsa.pub文件,如果没有,先生成ssh key;如果有,将其添加到github的SSH keys中。
然后继续push,又遇到问题:
github中默认分支是main,git中默认分支是master,推送时会在仓库中新增一个分支,因此不推荐该方法。
解决:关于git的问题:error: src refspec main does not match any_gongdamrgao的博客-CSDN博客
-
方法二
将仓库克隆到本地,合并为public文件夹。然后git push即可。
-
-
push之后等待page部署完成即可查看网站。
6 配置Utterances添加评论功能
utterances 是一款基于 github issues 的评论系统
-
安装utterances:点击https://github.com/apps/utterances,按照提示操作,把上面存放博客的repo的权限给utterances。操作完成后,在username.github.io这个repo的Settings->Integrations里可以看到utterances。
-
修改博客的全局配置config.toml。
[params.utterances] # https://utteranc.es/ owner = "jincheng9" # Your GitHub ID repo = "jincheng9.github.io" # The repo to store comments
-
重新部署博客,就可以在文章下面看到评论区了,正如本篇文章最下面的评论区一样。
$ hugo$ hugo server
-
注意:每次自己本地的修改,需要先执行
hugo
命令来更新public下的内容,再进入public目录把修改push到GitHub上,才能保证互联网访问的内容是更新后的,否则修改只会停留在本地。
7 some solutions to bug
ref:Hugo + even + GitHub Pages+ Utterances搭建个人博客 - SegmentFault 思否
更多推荐
所有评论(0)