Featured image of post Read Me

Read Me

About this Blog

Hugo + Github 笔记

【教程】Hugo+Github博客部署

文章管理

放在最前面方便看

创建文章:

1
hugo new post/一级分类/二级分类……/post_name/index.md

post/一级分类/二级分类……/post_name/下新建一个文件夹用于存图(typora自己建好了)

注意:

1
![image-20250403143026963](./assets/image-20250403143026963.png)

要改成:

1
![image-20250403143026963](assets/image-20250403143026963.png)

否则识别不到

只有封面图片可以直接放在直接文件夹下

定义分类、标签:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
tags : [
    "markdown",
    "css",
    "html",
    "themes",
]
categories : [
    "themes",
    "syntax",
]

放在最前面的模板

tag可以随便取,分类建议大一点

不需要其他指令去单独建立tag或分类,直接文章里用到就会自动建立

相册语法

Images in Markdown - Typlog Docs

1
2
3
![Photo by Florian Klauer on Unsplash](florian-klauer-nptLmg6jqDo-unsplash.jpg)  ![Photo by Luca Bravo on Unsplash](luca-bravo-alS7ewQ41M8-unsplash.jpg) 

![Photo by Helena Hertz on Unsplash](helena-hertz-wWZzXlDpMog-unsplash.jpg)  ![Photo by Hudai Gayiran on Unsplash](hudai-gayiran-3Od_VKcDEAA-unsplash.jpg)

效果: image-20250403143026963

Install

先装一下git

下载hugo的zip:Releases · gohugoio/hugo

教程选的是hugo_extended_xxx_windows版本

把压缩包里的hugo.exe拖到自己的某个文件夹内

1
hugo new site sci-biribiri

创建文件夹

然后cd进去,并且把hugo.exe也拖进去这个文件夹方便使用

1
cd sci-biribiri

运行服务:

1
hugo server -D

这个时候某个端口就会开始运行hugo,不出意外显示一个Page Not Found

主题部署

Complete List | Hugo Themes

我选的这个主题:CaiJimmy/hugo-theme-stack: Card-style Hugo theme designed for bloggers

releases下载source code进行解压

解压到sci-biribiri/themes目录下

把主题文件内的exampleSite/contentexampleSite/hugo.yaml直接复制到主文件夹sci-biribiri

如果你是stack主题,请删掉content/post/rich-content/,否则会无法启动

删掉主文件夹sci-biribirihugo.toml,到此完成配置文件的替换

注意到此时hugo.yaml是这样的:

1
2
3
4
5
baseurl: https://example.com/
languageCode: en-us
theme: hugo-theme-stack
title: Example Site
copyright: Example Person

识别的主题是:hugo-theme-stack

因此要确保sci-biribiri/themes下的主题文件夹的名字要对应上

我这里修改sci-biribiri/themes/hugo-theme-stack-3.30.0sci-biribiri/themes/hugo-theme-stack

1
hugo server -D

后面就是慢慢自己调内容

记得修改archetypes\default.md,每次创建文章的模板是按照这个模板做的

1
2
3
4
5
6
7
8
9
title: "{{ replace .Name "-" " " | title }}" # 标题,创建时自动填充
description: # 文章简介
date: {{ .Date }} # 日期,创建时自动填充,格式同 2023-01-15T12:00:00+08:00
image: # 文章的封面,留空就是没有,填文章所在位置的相对地址,通常放在同目录下,
math: # 是否启用 KaTex,填 true 启用
license: # 文章尾部显示的协议,false 为隐藏,其他作为内容,留空就是使用 config.yaml 里默认的
hidden: false # 是否隐藏,一般用不到
comments: true # 因为 bug 所以这个属性只要存在,不管是 true 还是 false 都会导致回复无法显示,需要删掉
draft: true # 是否为草稿,建议改为 false 或者删掉这个属性以防止忘记修改,毕竟我们一般都是写好了才部署到服务器上

推荐:

1
2
3
4
5
6
7
8
title: "{{ replace .Name "-" " " | title }}" 
description: 
date: {{ .Date }} 
image: 
math: true
draft: false 
tags: []  # 双引号
categories: [] # 双引号
使用 Hugo 构建
主题 StackJimmy 设计