Skip to content

tiggerlee/killthatman

Repository files navigation

杀死那个碳基人

一个使用 Hugo + LoveIt 搭建的中英双语博客。

项目约定

  • 默认语言是中文,路径前缀为 zh-cn
  • 英文作为翻译版本,路径前缀为 en
  • 写作流程是先写中文,再补对应英文译文
  • 中英文对应文章通过相同的 translationKey 关联

目录结构

.
├── archetypes/           # 新文章默认模板
├── content/zh-cn/        # 中文内容
├── content/en/           # 英文内容
├── themes/LoveIt/        # LoveIt 主题
└── hugo.toml             # 站点配置

主题

  • 当前主题:LoveIt
  • 主题目录:themes/LoveIt/
  • 站点配置已在 hugo.toml 中启用 theme = "LoveIt"

本地启动

hugo server -D

默认会生成两个语言入口:

  • 中文:http://localhost:1313/zh-cn/
  • 英文:http://localhost:1313/en/

参数说明:

  • -D 表示草稿也会显示出来
  • 如果文章还是 draft = true,只有带 -D 启动时才会看到

新建文章

中文原文:

hugo new content zh-cn/posts/my-first-post.md

英文译文:

hugo new content en/posts/my-first-post.md

如果你想一次性创建中英文文章和图片目录,直接使用仓库脚本:

scripts/new-post my-first-post

这个脚本会自动:

  • 创建 content/zh-cn/posts/my-first-post.md
  • 创建 content/en/posts/my-first-post.md
  • 为两篇文章写入相同的 translationKey
  • 写入 featuredImage
  • 创建 static/images/posts/my-first-post/

还支持创建时顺手写入分类和标签:

bash scripts/new-post my-first-post \
  --tags "hugo,blog" \
  --categories "notes"

如果中英文需要不同的分类或标签,可以分别指定:

bash scripts/new-post my-first-post \
  --tags "hugo,blog" \
  --zh-tags "中文" \
  --en-tags "english" \
  --categories "notes" \
  --zh-categories "写作" \
  --en-categories "writing"

可用参数:

  • --tags:中英文共用标签
  • --categories:中英文共用分类
  • --zh-tags:只写入中文文章标签
  • --en-tags:只写入英文文章标签
  • --zh-categories:只写入中文文章分类
  • --en-categories:只写入英文文章分类

生成后的文章默认模板在 archetypes/default.md,会包含这些字段:

title = ""
date = 2026-03-12T13:00:00+08:00
draft = true
translationKey = ""

字段含义:

  • title:文章标题
  • date:发布日期
  • draft:是否为草稿
  • translationKey:中英文文章的对应标识

双语文章关联

建议为中英文对应文章填写相同的 translationKey。例如:

title = "示例"
date = 2026-03-12T13:00:00+08:00
draft = false
translationKey = "my-first-post"

中文文章示例:

title = "我的第一篇文章"
date = 2026-03-12T13:00:00+08:00
draft = false
translationKey = "my-first-post"

英文文章示例:

title = "My First Post"
date = 2026-03-12T13:00:00+08:00
draft = false
translationKey = "my-first-post"

这样 Hugo 会在文章页自动显示语言切换链接。

内容放置规则

  • 中文文章放在 content/zh-cn/posts/
  • 英文文章放在 content/en/posts/
  • 中文首页内容在 content/zh-cn/_index.md
  • 英文首页内容在 content/en/_index.md

如果只是写普通文章,直接放进各自语言下的 posts/ 目录即可。

图片使用规则

建议把文章相关图片统一放在:

static/images/posts/<文章slug>/

例如测试文章的图片目录是:

static/images/posts/loveit-test-post/

文章题图

题图建议固定命名为:

static/images/posts/<文章slug>/cover.png

然后在文章 front matter 里填写:

featuredImage = "/killthatman/images/posts/<文章slug>/cover.png"

例如:

featuredImage = "/killthatman/images/posts/loveit-test-post/cover.png"

这样有几个好处:

  • 首页文章列表能正常显示题图
  • 文章页能正常显示题图
  • LoveIt 的分享图和 SEO 图片也会优先使用它

如果这是一篇中英文对应文章,通常两篇文章共用同一张题图即可。

文章正文插图

正文里插入的图片,也建议放在同一个目录下:

static/images/posts/<文章slug>/

例如:

static/images/posts/my-first-post/diagram-01.png
static/images/posts/my-first-post/screenshot-01.png

正文中引用时,建议写站内绝对路径:

![图示](/killthatman/images/posts/my-first-post/diagram-01.png)

不要在正文里使用像下面这样的相对路径:

![图示](../../../images/posts/my-first-post/diagram-01.png)

原因是:

  • 相对路径在文章页里可能能显示
  • 但首页列表、摘要、卡片或其他上下文里可能会失效

什么时候用 featuredImage

  • 用作文章题图时:写进 front matter 的 featuredImage
  • 只是正文中的普通插图时:直接在 Markdown 里用 ![](...)

如果一张图既想作为题图,又想出现在正文中,可以两边都写。

路径约定

当前站点部署在 GitHub Pages 项目路径下:

https://tiggerlee.github.io/killthatman/

因此图片路径统一以 /killthatman/ 开头,例如:

/killthatman/images/posts/loveit-test-post/cover.png

如果以后域名或部署方式变了,这一部分路径规则也要一起调整。

写作注意事项

当前站点已经启用了这些能力:

  • 代码高亮
  • 代码块复制按钮
  • 数学公式渲染
  • Mermaid 图表
  • 自动目录

代码块

直接使用 fenced code block:

```go
package main

import "fmt"

func main() {
    fmt.Println("hello")
}

常见语言标记可以直接写在代码块后面,例如 `go`、`python`、`js`、`ts`、`bash`、`json`。

### 数学公式

行内公式:

```md
当 $n \to \infty$ 时,$\frac{1}{n} \to 0$。

块级公式:

$$
\\int_0^1 x^2 \\, dx = \\frac{1}{3}
$$

数学公式转义规则

这是最容易踩坑的地方。

  • 行内公式通常可以直接写单反斜杠,例如 \frac\to
  • 块级公式里如果用了 LaTeX 命令,建议把反斜杠写成双反斜杠,例如 \\frac\\int
  • 如果是矩阵换行,LaTeX 里的 \\ 在 Markdown 中还要再转义一层,所以要写成 \\\\

矩阵示例:

$$
A =
\\begin{bmatrix}
1 & 2 \\\\
3 & 4
\\end{bmatrix}
$$

如果你发现公式被显示成一行,优先检查是不是反斜杠写少了。

Mermaid 图表

可以直接写:

```mermaid
flowchart TD
    A[写中文] --> B[翻译成英文]
    B --> C[发布文章]

### 目录

文章里只要使用二级、三级标题,LoveIt 就会自动生成目录。例如:

```md
## 第一节
### 小节
## 第二节

双语文章

中英文对应文章要填写相同的 translationKey

translationKey = "my-first-post"

这样文章页会自动出现语言切换链接。

草稿

  • draft = true:默认不会出现在正式构建中
  • draft = false:会正常发布

本地预览草稿时使用:

hugo server -D

参考示例

仓库里已经有一组测试文章,可以直接对照着写:

  • 中文:content/zh-cn/posts/loveit-test-post.md
  • 英文:content/en/posts/loveit-test-post.md

发布前检查

生成静态文件:

hugo

生成结果默认在 public/ 目录。

发布前至少检查这些内容:

  • 中文首页是否正常:/zh-cn/
  • 英文首页是否正常:/en/
  • 文章是否出现在对应语言列表页
  • 中英文文章之间是否能互相跳转
  • 准备上线的文章是否已经改成 draft = false

GitHub Pages 自动部署

仓库已经添加 GitHub Actions 工作流:

  • 工作流文件:.github/workflows/hugo-gh-pages.yml
  • 推送到 main 分支时会自动构建并部署到 GitHub Pages

部署前需要在 GitHub 仓库页面手动确认这几项:

  1. 打开仓库的 Settings
  2. 进入 Pages
  3. Build and deployment 中选择 Source: GitHub Actions

当前站点的 baseURL 已经配置为:

https://tiggerlee.github.io/killthatman/

这对应的是 GitHub Pages 的项目站点模式:

https://<github用户名>.github.io/<仓库名>/

也就是:

https://tiggerlee.github.io/killthatman/

注意事项

  • 主题 themes/LoveIt 是 Git 子模块,推送代码时要把 .gitmodules 和子模块引用一起提交
  • public/resources/ 属于构建产物,已经加入 .gitignore
  • 当前工作流监听 mastermain
  • 如果以后仓库默认分支改成别的名字,要同步修改工作流里的分支名

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors