跳转至

配置参考

站点配置分三处:config/ 下按环境拆分的 Hugo 配置,data/ 下被模板当作配置读取的 YAML,以及仓库根目录的几个工具配置文件。本页说明每个文件管什么,并列出模板和脚本确实读取的参数。查看合并后的最终配置用 hugo config。

config 目录

Hugo 先读 config/_default/,再用当前环境目录里的同名项覆盖。hugo server 默认是 development 环境,hugo 构建默认是 production 环境;仓库没有 production 目录,生产构建只读 _default。

文件 内容
config/_default/config.toml 根配置:baseURL、默认语言、ignoreFiles、[outputs]、[params]、[build]、[caches]、[pagination]、[imaging]、[markup]、[taxonomies]、[languages]、[minify]、[sitemap]
config/_default/params.toml 追加到 params 的分组:repository、search、plugins、preloader、ad、analytics
config/_default/socials.en.toml、config/_default/socials.zh.toml 各语言的社交账号列表 params.social
config/_default/podcast.zh.toml 中文站的播客频道信息 params.podcast
config/_default/related.toml 相关文章的匹配权重:tags 100、categories 50、date 10,阈值 80
config/development/config.toml 不生成 sitemap 与 robots.txt,关闭资源缓存并把缓存有效期缩到秒和分钟级
config/preview/config.toml baseURL 改为预览域名,构建草稿
config/preview/params.toml siteWideNoIndex = true,关闭全部统计

根配置要点

下表是 config/_default/config.toml 中决定站点行为的设置。[build] 与 [caches] 的含义见 构建与部署。

设置 当前值 效果
DefaultContentLanguage、defaultContentLanguageInSubdir en、false 英文是默认语言,URL 不带前缀;中文在 /zh/ 下
[languages.en]、[languages.zh] contentDir 分别为 content/en、content/zh 每种语言在自己的 params 下覆盖 description、job_title、company、copyright、address、notification 等参数
[outputs] 首页 HTML、RSS、JSON;栏目 HTML、RSS;其余只有 HTML 首页的 JSON 输出就是搜索索引,模板为 layouts/index.json
[taxonomies] categories、tags 只有这两种分类法
[pagination] pagerSize = 10 列表页每页 10 条
ignoreFiles 正则列表 构建时忽略图书目录里的 SUMMARY.md、README.md、image-caches,幻灯片源文件 slide.md,markmap.md,以及 .mmd、.ipynb、.zip、.psd、.mp4 等非内容文件
[markup.goldmark.renderer] unsafe = true Markdown 里的原始 HTML 会被输出
[markup.goldmark.parser.attribute] block = true、image = true 允许图片下一行的 {width=… height=…} 之类的属性写法
[markup.goldmark.extensions.passthrough] 块级 $$…$$,行内 \(…\) 数学公式的定界符;单个 $ 不是定界符,正文里的美元价格保持原样
[markup.highlight] style = "github"、noClasses = true 代码高亮使用内联样式
[markup.tableOfContents] startLevel = 2、endLevel = 4 目录收录二到四级标题
[imaging] resampleFilter = "lanczos"、quality = 75、anchor = "smart" Hugo 图片处理的默认参数
[sitemap] changefreq = "weekly"、priority = 0.4 默认值,输出模板是 layouts/sitemap.xml

不要设置 disableAliases

front matter 里的 aliases 依赖 Hugo 生成跳转页(模板 layouts/alias.html)。Cloudflare Pages 的 _redirects 只有前约 100 条规则生效,放不下全部历史路径。

导航菜单

仓库里没有 menus.*.toml,Hugo 的 menus 配置为空。菜单全部来自数据文件:

位置 定义 读取模板
顶部主导航 data/<lang>/homepage.yaml 的 main_menu,每项有 Name、URL、Identifier layouts/partials/header.html
主导航的下拉面板 data/<lang>/mega_menu.yaml;菜单项用 Params.mega: <键名> 关联到 mega 下的同名条目 layouts/partials/menu/mega-dropdown.html
页脚链接与社交图标 data/<lang>/homepage.yaml 的 footer layouts/partials/footer.html

模板读取的站点参数

下表只列在 layouts/ 中确实被读取的参数。未注明文件的参数定义在 config/_default/config.toml 的 [params]。

参数 读取位置 作用
logo layouts/partials/header.html 页眉标志。当前值会渲染成文字标 Jimmy/Song;只有不设 logo 时才使用 brand_icon 和 header_title
description、author、job_title、company、address layouts/partials/head.html、layouts/partials/head-seo.html、layouts/partials/structured-data.html、layouts/partials/enhanced-person-schema.html SEO 标签与结构化数据
copyright layouts/partials/footer.html、layouts/partials/book/book-content-layout.html 页脚版权行,按语言定义
default_cover layouts/partials/head-seo.html、layouts/partials/structured-data-get-image.html 页面没有配图时的分享图
email、wechat、social layouts/pages/about.html、layouts/shortcodes/contact-channels.html;social 还用于 layouts/partials/footer.html 关于页和联系页的公开联系方式与账号
enable_comment layouts/_default/single.html、layouts/partials/book/book-content-layout.html 与页面的 comment 同时为真才显示评论
enable_edit_on_github、repository.url、repository.branch layouts/partials/post-meta.html、layouts/partials/book/book-content-layout.html 与页面的 editable 同时为真才显示 GitHub 编辑链接,当前为 false
sourceDir layouts/_default/edit_icon.html、layouts/partials/post-meta.html 拼出内容源文件路径
images_repo_domain、baidu_map_api_key layouts/pages/travel.html、layouts/partials/travel_map_script_baidu.html 旅行页的图片域名与百度地图密钥
search.enable、search.provider、search.min_length、search.threshold layouts/partials/wowchemy-search.html 站内搜索开关、最短查询长度和 Fuse.js 模糊阈值
plugins.css、plugins.deferred_css layouts/partials/head-css.html 打包进 CSS bundle 的 assets/plugins/ 文件,deferred_css 中的条目改为异步加载
plugins.js、plugins.deferred_js layouts/partials/js-bundle.html 打包进 JS bundle 的 assets/plugins/ 文件,deferred_js 中的条目按页面需要加载
ad.enable_sidebar、ad.enable_bottom layouts/_default/single.html、layouts/partials/book/book-content-layout.html 广告位的全局默认值,页面 front matter 的 ads 可覆盖,见 广告配置
analytics.enable、analytics.provider、analytics.google、analytics.umami、analytics.events.lazy_load、analytics.events.enable_link_tracking layouts/partials/js-bundle.html、layouts/_default/_markup/render-link.html 统计脚本的开关与账号,hugo server 下一律不加载,见 Umami 统计
notification.*(各语言) layouts/_default/baseof.html、layouts/partials/toastr.html 右下角通知,enabled = true 时显示
podcast.*(中文) layouts/podcast/rss.xml、layouts/shortcodes/podcast.html 播客 RSS 的频道信息和 Apple Podcasts 节目 ID
siteWideNoIndex(preview) layouts/partials/head-seo.html 全站输出 noindex

模板还会读取几个目前没有配置的可选参数:dateformat(日期格式,默认取 i18n 的 dateFormat)、geo_region(默认 CN-BJ)、robots、books.order_by(图书侧栏排序,默认 weight)、contact_email、contact_phone。

配置文件里的 gcs_engine_id、wechat、anchored、section_header_image、preloader,以及 search 和 analytics.events 下未出现在上表的键,没有任何模板读取,修改它们不会有效果。

data 目录中的配置

模板通过 hugo.Data 读取这些文件。data/zh/ 与 data/en/ 下的文件按当前语言选取。

文件 作用
data/<lang>/homepage.yaml 首页各区块的文案与开关(seo、top_header、hero 等),以及主导航 main_menu 和页脚 footer,见 首页
data/<lang>/mega_menu.yaml 主导航下拉面板的内容
data/<lang>/ads.yaml 广告位文案与链接,由 layouts/partials/ad_sidebar.html 和 layouts/partials/ad_bottom.html 读取
data/<lang>/books.yaml 图书清单(目录名、路径、标题、分类、作者、年份),用于首页和书架
data/<lang>/book_covers.yaml 图书封面的 CDN 地址,由 npm run content:book-covers -- --upload 维护,不要手改
data/<lang>/profile.yaml 关于页与作者签名的个人信息
data/<lang>/oss.yaml 开源工具页的条目
data/<lang>/travel.yaml 旅行页的地点、坐标和照片
data/zh/schedule.yaml 日程页的活动列表,只有中文
data/statuses.yaml 状态徽章的图标、颜色和中英文标签,由 layouts/partials/status-badge.html 读取
data/category_config.yaml 各分类的图标与配色,由 layouts/_default/item_card.html 读取
data/terms.yaml 标签显示名映射(小写标签到规范写法)
data/glossary.yaml 术语表页面的数据
data/quizzes/ quiz 短代码的题库,每个 YAML 一套题
data/image_dimensions.json 远程图片的宽高登记表,由图片渲染钩子读取,上传脚本和 npm run content:images:add-dimensions 写入
data/wechat-templates.yaml 公众号发布的页眉页脚模板,按账号分组,由 scripts/content/publish-wechat-draft.js 读取
data/wechat-menu.yaml 公众号的自定义菜单和被关注回复,由 .agents/skills/wechat-mp/scripts/mp.mjs 读取并发布到后台
data/wechat-albums.yaml 公众号合集的自动归类规则(按标签、标题关键词、分类匹配),由 tools/wechat-markdown-exporter/src/backend-settings.js 读取

环境变量

下表列出脚本确实读取的变量,全部可选。make 目标的变量(ENV、FAST、DIR 等)见 Makefile 指南。

变量 读取位置 作用
HUGO_ENV、GOMAXPROCS scripts/site/run-hugo.js 未传 --environment 时的环境名;Hugo 使用的 CPU 核数
EXTRA_HTML_TRIM scripts/site/minify-html.js 为 true 才执行额外的 HTML 空行清理
SKIP_ANALYSIS scripts/site/generate-analysis-data.js 为 true 时跳过内容分析数据生成
SKIP_LINK_CHECK test/content.test.js 为 true 时跳过链接检查,npm run test:fast 会自动设置
SKIP_EXTERNAL_CHECK scripts/site/check-built-links.js 为 1 时只检查站内链接
FORCE_REUPLOAD、VERBOSE、QUIET、DEBUG_UPLOAD_IMAGES scripts/content/upload-images.js 为 1 时分别表示:远端已有同名文件也重传、输出详细日志、静默、打印调试信息
PUPPETEER_EXECUTABLE_PATH scripts/content/book-covers/index.js 指定渲染封面用的浏览器
OUT_DIR scripts/content/generate-content-index.js、scripts/content/seo-audit.js、scripts/content/related-posts-map.js 报告输出目录,默认 reports
TAG_MIN_COUNT scripts/content/remove-tags-by-frequency.js 低于该次数的标签会被移除,默认 3
LENIENT_VALIDATION scripts/docs/validate-documentation.js 设置后文档校验使用宽松模式
WEBSITE_ROOT tools/mcp/website-mcp-server.ts MCP 服务器使用的仓库根目录

上表不含凭证类变量。公众号发布、清除 CDN 缓存、图片上传和 Worker 同步用到的凭证与地址变量见仓库内的 docs-internal/infrastructure.md。

根目录的工具配置

文件 作用
postcss.config.js Hugo 的 PostCSS 管道配置,只启用 autoprefixer。PurgeCSS 已停用,config/_default/config.toml 相应设置了 writeStats = false
frontmatter.json VS Code 扩展 Front Matter CMS 的配置:各内容类型的字段、内容目录和自定义脚本按钮,见 Front Matter CMS
mermaid-config.json scripts/content/transform-mermaid.js 渲染 Mermaid 时使用的主题
.htmltest.yml GitHub Actions 中 htmltest 站内链接检查的规则
.markdownlint.json test/markdownlint.test.js 使用的 Markdown 规则
mkdocs.yml、mkdocs.local.yml 本文档站的 MkDocs 配置,后者供 make docs 本地预览使用