Featured image of post Hugo + Github Page 快速搭建部落格

Hugo + Github Page 快速搭建部落格

缘起

原本有一篇文章是关于如何使用github page 搭建部落格,由于配置系统的时候丢失了,故今日快速重写一篇,顺便藉此提高自己写作的速度,下载就以stack 爲例

准备

  1. 准备一个github 账户,如果没有就注册一个
  2. 创建两个repo, 一个名爲hugo-stack, 另一个爲github.用户名.>
  3. 安装hugo
  • Windows 系统可以参考此链接 或者官方文档
  • ArchLinux: sudo pacman -S hugo
  • 其他发行版使用自带包管理工具直接安装 hugo即可

开始

  1. 生成一个hugo 工作资料夹
1
hugo new site hugo-stack # hugo-stack 爲资料夹名称
  1. 初始化repo及将stack 主题以submodule形式clone到本地
1
2
git init
git submodule add https://github.com/CaiJimmy/hugo-theme-stack themes/hugo-theme-stack
  1. 将stack 主题的配置copy 到根目录
1
2
3
4
5
6
7
8
cp -r themes/hugo-theme-stack/exampleSite/content ./
cp -r themes/hugo-theme-stack/exampleSite/config.yaml ./
cp -r themes/hugo-theme-stack/archetypes ./
cp -r themes/hugo-theme-stack/data ./
cp -r themes/hugo-theme-stack/assets ./
cp -r themes/hugo-theme-stack/i18n ./
cp -r themes/hugo-theme-stack/layouts ./
cp -r themes/hugo-theme-stack/assets ./
  1. 运行博客 hugo server -D
  • 在终端按住Ctrl 键点击 http://localhost:*/ 开啓预览网站,或者複製 http://localhost:*/ 粘贴到浏览器开啓,* 代表系统分配的端口名

stack_sample

简单配置Blog

按需修改以下配置,添加到根目录的config.yaml

  1. 默认语言与域名配置
1
2
3
4
5
6
7
baseurl: https://github.用户名.io ## hugo 生产静态网页存放的域名
languageCode: en-us
theme: hugo-theme-stack
paginate: 5

defaultContentLanguage: zh-tw # 默认语言
title: Black Lu # 标题
  1. 修改副标题和头像
1
2
3
4
5
6
7
    sidebar:
        emoji: 🍥
        subtitle: 我的语言之局限,即是我的世界之局限 # 副标题
        avatar:     
            enabled: true
            local: true
            src: img/avatar.png #头像存放在根目录的 assets/img 下
  1. 添加最后更新与 字段
1
2
3
dateFormat:
    published: Jan 02, 2006
    lastUpdated: Jan 02, 2006 15:04 MST

推送到远程repo

  1. 将目录推送到 hugo-stack repo
1
2
3
4
5
6
git init
git add .
git commit -m "Intitial commit"
git branch -M main
git remote add orgin git@github.com:LucasBlackLu/hugo-stack.git
git push -u origin main
  1. 将 Pulic 的内容推送到 github.用户名.io repo
1
2
3
4
5
6
7
cd public
git init
git add .
git commit -m "Intitial commit"
git branch -M main
git remote add orgin git@github.com:LucasBlackLu/lucasblacklu.github.io.git
git push -u origin main
  • Public 资料夹里面的是构建静态网页的资源,直接push 到 github.用户名.io Repo, 在浏览器输入 github.用户名.io 即可查看你部署好的Blog

注意事项

  1. Page Bundle

hugo使用Page Bundle 的文件结构,如下

1
2
3
4
5
6
tree archlinux_install

/archlinux_install
├── arch.png
├── etcher.png 
└── index.md
  1. 新建文章命令爲
1
hugo new post/new_post/index.md # new_post 改成你文章的英文名字

结语

本文主要是爲填补以前挖下的坑,剩下的坑还有git, rom 编译等,祝各位好运

参考与致谢

Built with Hugo
主题 StackJimmy 设计