
start-hugo
- xxcdu
- Application , Data
- April 4, 2022
Table of Contents
一、start hugo
条件:配置好git,下载hugo,将hugo所在目录放入环境变量
1、创建网站:
hugo new site /path/to/site
;
2、克隆主题:
git clone https://github.com/vaga/hugo-theme-m10c.git themes/m10c
;(具体方式看主题中的介绍)
主题网址:https://themes.gohugo.io/
下载主题后进入hugo.toml或config.toml修改theme
3、启动:
hugo server -t m10c --buildDrafts
4、新建文章:
hugo new post/test01.md
5、部署到github:
hugo --theme=m10c --baseURL="https://xxcdu.github.io/" --buildDrafts
生成一个public文件夹
6、进入public后,传入github:
git init
git add .
git commit -m " "
7、将public远程关联到
github:git remote add origin https://github.com/xxcdu/xxcdu.github.io/
8、将public推上去:
git push -u origin master
9、更新:
生成新的public,git add 、commit推送到github
10、本地启动服务用hugo server -D
git add时提示“warning: LF(换行) will be replaced by CRLF(回车换行)”:
成因:
Dos和Windows平台: 使用回车(CR)和换行(LF)两个字符来结束 一行,回车+换行(CR+LF),即“\r\n”;Mac 和 Linux平台:只使用换行(LF)一个字符来结束一行,即“\n”。 许多 Windows 上的编辑器会悄悄把行尾的换行(LF)字符转换成回车(CR)和换行(LF),或在用户按下 Enter 键时,插入回车(CR)和换行(LF)两个字符。
解决:
提交时转换为LF,检出时转换为CRLF
$ git config --global core.autocrlf true
纯windows:#提交检出均不转换
$ git config --global core.autocrlf false
初次运行git时SSL certificate problem: unable to get local issuer :
certificate错误的成因:当通过HTTPS访问Git远程仓库的时候,如果服务器上的SSL证书未经过第三方机构认证,git就会报错。 解决方法:需关掉sslverify :
git config --system http.sslverify false #当前用户
git config --global http.sslverify false #全局用户
git config http.sslverify false #当前仓库
二、更新hugo
1、在根目录下builddrafts生成public文件夹,例如:
hugo --theme=hugoplate --baseURL="https://xxcdu.github.io/" --buildDrafts
2、进入public文件夹
3、添加到git
git add .
4、提交git
git commit -m " "
5、push到远程仓库
git push -u origin master
三、hugo常见问题
1、github部署hugo博客后,可能出现文章地址被重定向到localhost的情况,这时需要在仓库中将index.html和index.xml中的文章url改为仓库url,即../post/…..
2、若在github远端修改仓库代码,则在将public push时可能会出现:
error: failed to push some refs to 'https://github.com/xxcdu/xxcdu.github.io/'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
显示远端被修改。这时需要先拉取远程更改:
git pull origin master
在本地分支上更改冲突文件,再git add 提交推送。
3、远程部署后,想在本地启动服务并修改网站文件,使用“hugo server -t m10c –buildDrafts”可能出现本地服务启动后,主页中没有文章链接的情况,这时查看public根目录文件夹的index.html时,发现根本没有与链接文章url有关的的部分。
更新public后,使用“hugo server -D”启动服务后主页出现了文章链接,但点开后跳转到了远程服务器的地址如https://xxcdu.github.io/post/start-hugo/而不是本地文章地址http://localhost:1313/post/hugo-github%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98/,这可能是由于url冲突,需配置好网站根目录下的hugo.toml文件,将baseURL设置为远程部署的地址url。修改后发现已可以在访问本地站点。且注意使用时不要通过