配置

Snow 使用 YAML 格式配置,默认为站点根目录下的 config.yaml,可通过 --config 参数指定其他文件。

站点信息

配置项 类型 默认值 说明
base_url string http://127.0.0.1:8000 站点根 URL
title string snow 站点标题
description string snow is a static site generator. 站点描述
author string honmaple 站点作者
language string en 默认语言代码

目录

配置项 默认值 说明
output_dir output 构建输出目录

Snow 使用固定项目目录:content/static/templates/themes/。这些目录名不可通过配置修改;主题名称仍通过 theme 配置选择,对应 themes/{theme}/

内容处理

配置项 类型 默认值 说明
content_truncate_len int 49 摘要截取长度
content_truncate_ellipsis string ... 摘要后缀
ignored_content []string 忽略内容 glob
ignored_static []string 忽略静态文件 glob

ignored_contentignored_static 按相对路径匹配。以 _. 开头的内容文件默认忽略,_index.{md,org,html} 除外。

多环境 (Modes)

1base_url: "http://127.0.0.1:8000"
2
3modes:
4  publish:
5    base_url: "https://example.com"
6  develop:
7    debug: true
8    include: "develop.yaml"

通过 --mode publish 构建时,base_url 等配置会被覆盖。include 可引用外部文件合并配置。

语法高亮 (Markups)

 1markups:
 2  _default:
 3    style: "monokai"
 4    show_toc: true
 5    show_line_numbers: true
 6    prevent_pre_code: true
 7  markdown:
 8    enabled: true
 9    unsafe: false
10    directive_blocks: false
11  orgmode:
12    enabled: true
13  niklasfasching:
14    enabled: false
15  html:
16    enabled: true
配置项 类型 默认值 说明
enabled bool Markdown/Org-mode 为 true,HTML/niklasfasching 为 false 是否启用该解析器
style string monokai chroma 语法高亮样式
show_toc bool true 显示文章目录
toc_id string 自动生成目录锚点的方式,可选 titleindex;为空时使用默认标题锚点
show_line_numbers bool true 显示行号
prevent_pre_code bool true 高亮代码块时避免额外包裹 pre/code
unsafe bool false Markdown 专用;允许 goldmark 输出原始 HTML
directive_blocks bool false Markdown 专用;启用 :::export html:::center:::quote:::shortcode 指令块

常见样式:monokaigithubdraculasolarized-dark

markups._default 为所有解析器提供默认渲染选项;markups.markdownmarkups.orgmodemarkups.niklasfaschingmarkups.html 可以分别覆盖。默认启用 Markdown 和 Org-mode,HTML 与 niklasfasching parser 已内置注册但默认未启用。解析器行为见 解析器

输出格式 (Formats)

1formats:
2  rss:
3    template: "partials/rss.xml"
4  atom:
5    template: "partials/atom.xml"

每个内容类型可通过 formats.{name}.pathformats.{name}.template 覆盖默认值。

Section 配置

 1sections:
 2  _default:
 3    path: "{path:slug}/"
 4    sort_by: "date desc"
 5    paginate: 0
 6  posts:
 7    sort_by: "date desc"
 8    paginate: 5
 9    template: "custom.html"
10  pages:
11    path: ""

配置查找:sections.{目录名} → 父目录 → sections._default

关键配置项 默认值 说明
path {path:slug}/ 输出路径,为空禁用渲染
path_style - 输出路径后处理,见 Path Style 配置
sort_by date desc 页面排序
paginate 0 分页数,0 不分页
paginate_path 自动 分页路径
template 无默认,按 section.html 查找

未设置或设为空字符串时,分页器会按输出路径类型选择默认值:pretty 路径使用 page/{number}/,ugly 路径使用 {name}{number}{extension};详见 分页

Page 配置

 1pages:
 2  _default:
 3    path: "{path:slug}/{slug}/"
 4  posts:
 5    path: "articles/{date:%Y}/{date:%m}/{slug}.html"
 6  pages:
 7    hidden: true
 8    template: "page.html"
 9  drafts:
10    draft: true

配置查找:pages.{目录名} → 父目录 → pages._default

关键配置项 默认值 说明
path {path:slug}/{slug}/ 输出路径
path_style - 输出路径后处理,见 Path Style 配置
template 无默认,按 page.html 查找
draft false 标记为草稿
hidden false 隐藏页面
lang 站点配置 语言

Path Style 配置

path_style 用于在路径变量解析后做统一后处理,可用于 Page、Section、Taxonomy 和 Taxonomy Term。可选值为 nonelowerslugslug_unicode,也可以用逗号按顺序组合,例如 lower,slug

说明
none 或空字符串 保持解析后的路径不变
lower 将输出路径全部转为小写
slug 按路径段 slug 化,并保留最后一个文件扩展名
slug_unicode 按路径段 slug 化并保留 Unicode 字符,不受 slugify.preserve_unicode 配置影响

Slugify 配置

1slugify:
2  lowercase: true
3  preserve_unicode: false
4  preserve_chars: ""

Slugify 配置用于 {slug}{path:slug}{title:slug}{term:slug}path_style: slug。默认会将 Unicode 字符转写为 ASCII,例如中文标题会生成类似 ni-hao-world 的 slug;如果希望保留中文等 Unicode 字符,可以设置 slugify.preserve_unicode: true

关键配置项 默认值 说明
lowercase true 是否转为小写
preserve_chars 空字符串 额外允许保留的字符,例如 +.
preserve_unicode false 是否保留 Unicode 字母和数字,例如中文;默认会转写为 ASCII

Taxonomy 配置

 1taxonomies:
 2  _default:
 3    path: "{taxonomy}/"
 4    sort_by: "name"
 5    term:
 6      path: "{taxonomy}/{term:slug}/"
 7      sort_by: "date desc"
 8  tags:
 9  categories:
10  authors:

只需在 taxonomies 下列出名称即可启用。配置查找:taxonomies.{name}.{key}taxonomies._default.{key}

Hook 配置

默认启用 assetsencryptlinksshortcode。其他内置 Hook 只设置默认权重,不会自动挂载:

Hook 默认启用 默认权重
mount false 5
snakecase false 10
assets true 20
pelican false 30
rewrite false 30
filter false 40
encrypt true 50
links true 55
shortcode true 60
minify false 70
alias false 80

weight 越小越先执行;权重相同时按 Hook 名称排序。如果显式配置 hooks.<name>.enabled: true,但对应 Hook 未注册,构建会返回错误。各 Hook 的具体配置见 插件

多语言

1language: "zh"
2
3languages:
4  en:
5    translations: "i18n/en.yaml"
6  fr:
7    translations:
8      - id: "tags"
9        tr: "Tags"

每个语言可覆盖任何全局配置。

主题

1theme: "snow"
配置项 默认值 说明
theme 主题名称,对应 themes/ 下的目录名

©2026 · 红枫文档