开始使用zola博客

七月 19, 2025 更新: 八月 08, 2026 [杂项]

安装zola

git clone https://github.com/getzola/zola.git
cd zola
cargo install --path . --locked
zola --version

配置博客

zola init blog
cd blog
git submodule add https://github.com/salif/linkita.git themes/linkta
# The URL the site will be built for
base_url = "https://blog.example.com"

title = "peter的博客"
description = "学海无涯"
default_language = "zh"
generate_rss = true

# Whether to automatically compile all Sass files in the sass directory
compile_sass = false

# theme = "even"
theme = "linkita"

# Whether to do syntax highlighting
# Theme can be customised by setting the `highlight_theme` variable to a theme supported by Zola
highlight_code = true
highlight_theme = "monokai"

# Whether to build a search index to be used later on by a JavaScript library
build_search_index = false

ignored_content = ["*.sw?"]

taxonomies = [
    {name = "categories", rss = true, paginate_by = 10},
    {name = "tags", rss = false, paginate_by = 10},
]

[extra]
# Put all your custom variables here

[extra.author]
name = "peter xiaoli"
email = "moxuetianya@gmail.com"

新建博客脚本

#!/bin/bash
# Copyright (c) 2025 peterxiaoli<moxuetianya@gmail.com>. All rights reserved.
# Use of this source is governed by General Public License that can be found
# in the LICENSE file.

set -xe
# Create a new article template.

ARTICLE=$1
if [ -z "${ARTICLE}" ]; then
  echo "Usage $0 article-name"
  exit 1
fi
TIMESTAMPE=$(date --rfc-3339=seconds)
FILENAME="content/$(date +%Y-%m-%d)-${ARTICLE}.md"
URL_PATH="$(date +%Y)/$(date +%m)/${ARTICLE}"
echo "TIMESTMAP: ${TIMESTAMPE}"
echo "FILENAME: ${FILENAME}"
echo "URL_PATH: ${URL_PATH}"

if [ ! -f "${FILENAME}" ]; then
  cat > "${FILENAME}" << EOF
+++
title = "${ARTICLE}"
description = ""
date = ${TIMESTAMPE}
path = "${URL_PATH}"
[taxonomies]
categories = []
+++
EOF
fi

内容维护:最近更新列表与自动同步

updated 字段与"最近更新"页

abridge 主题支持 frontmatter 的 updated 字段(config.toml 里 meta_post.updated = true 时文章页会显示"更新于")。基于它做了"最近更新"列表页(/updated/,菜单入口),按更新时间降序显示前 30 篇。

scripts/sync-updated.sh(核心脚本)

作用(幂等,可重复跑):

  1. 同步 updated 字段:对每篇文章取 git log 最后修改日期,与 frontmatter date 不同则写入 updated = "YYYY-MM-DD"
  2. 生成列表页:收集所有带 updated 的文章,按更新时间降序,重新生成 content/updated.md(链接用 @/ 内部链接语法)

注意:它读的是 git 历史——未提交的改动读不到;跑完会改 content/,需要重新提交。

post-commit hook:提交后自动同步

# 版本化 hook 放仓库里,git 通过 core.hooksPath 使用(新克隆只需跑一次)
git config core.hooksPath scripts/hooks

scripts/hooks/post-commit 做的事:提交后自动跑 sync-updated.sh,若有变化则只暂存脚本动过的文件,自动提交 chore: sync updated dates。幂等设计(无变化不产生提交,不会无限循环),仅 master 分支生效。

工作流:写文章 → 提交 → hook 自动同步 updated + 刷新列表 → 自动提交 → push 即部署。

视图与内容的关系

文章正文只渲染一份(各 URL 唯一);归档/最近更新/标签/首页都是"链接 + 元数据"的视图页,不复制正文。唯一真正复制内容的是分类 RSS feed(atom.xml,协议要求全文)。