Zeqiang Fang 方泽强

2019年7月27日 · 原文归档

基于Hugo与Github建立自己的博客

技术栈

为了总结经验,笔者借此写下利用hugo与github来建立自己的博客的经验,欢迎交流

安装Hugo

这个过程详见另一个博主的教程 Hugo + Github Pages 搭建个人博客

初始化Hugo项目

hugo new site [your-project-name]

这里以笔者的项目为例

hugo new fzqblog

载入主题

同样以笔者为例子,进入项目,从github上当一个主题下来(该主题为笔者喜爱的,有兴趣可以选择自己的)

主题会保存在项目博客根目录下的themes文件夹里

cd fzqblog
git clone https://github.com/olOwOlo/hugo-theme-even themes/even

预览Hugo静态网页

进入 fzqblog/themes/even/exampleSite 目录中,将 config.toml 文件与content 文件夹拷贝到项目根目录下即 fzqblog/ ,提示是否替换点击是的。

终端输入命令,启动 Hugo ,打开 http://localhost:1313/ 可预览:

hugo server

添加新的博客文章

hugo new post/new-article.md

相关模板配置信息如下:

---
title: "{{ replace .TranslationBaseName "-" " " | title }}"
date: {{ .Date }}
description: ""
draft: false
---

<!--more-->

打包

其中even是主题名称

hugo -t even

部署到 Github Pages

# 删除打包文件夹
rm -rf public

# 打包(even是主题,用户根据自己主题名具体操作)
hugo -t even 

# 进入打包后生成的public文件夹
cd public

# Add changes to git | 创建git命令
# -A 表示所有内容
git init
git add -A 

# Commit changes | 添加允许此次变更的说明
msg = "building site `date`"
git commit -m "$msg"

# 推送到github
git push -f [your-SSH-key] master

其它

参考博文 主题样例预览