The crafting shortcode previously depended on scripts/sync-items.py to pre-populate assets/items/ before every build: the script regex-scanned content/ for shortcode usages, listed the sfcraft repo via the GitHub API, downloaded missing vanilla textures from the wiki, and had to be driven through scripts/build.py, scripts/dev.py or a Makefile so that plain `hugo` never ran on its own. Resolution now happens inside the render pipeline, so `hugo` and `hugo server` work directly and nothing has to be kept in sync: - layouts/_partials/sfcraft/item-texture.html resolves an item id to an image Resource, trying assets/items/<id>.png, then the sfcraft repo texture, then the Minecraft wiki. - layouts/_partials/sfcraft/wiki-lookup.html derives the wiki English name from the id, lists candidates via the allimages API and picks the newest JE/BE render, replacing the script's name-variant logic. - Callers go through partialCached keyed on the item id, so each id is resolved once per build no matter how many slots reference it. Because usages are discovered by rendering, the content scanner is gone and the two syntaxes can no longer drift apart from what the scanner understood. Enumerating the sfcraft repo is also unnecessary: a texture is fetched by its raw URL and a 404 simply means "not a custom item". Caching is Hugo's getresource file cache, pinned to maxAge -1, so every URL is downloaded once globally, later builds hit the cache, and offline builds succeed. `hugo --ignoreCache` refreshes upstream changes, which replaces the script's per-build file-size comparison. Error reporting distinguishes cases the script could not tell apart. A 404 from every source means the id is wrong and fails the build (configurable via params.itemTextures.onMissing), while a transport error, rate limit or 5xx only warns and falls back to the `?` placeholder, so a missing network no longer looks like a typo. Also in this change: - wiki name special cases move from a dict in the script to data/sfcraft/wiki_aliases.yaml - textures publish to /sfc/items/<id>.png regardless of source, so switching an item to a hand-placed texture keeps its URL - component CSS moves to assets/css/sfcraft-crafting.css, minified and inlined once per page, instead of a heredoc inside the shortcode - a `.` used as an alias value now means "empty slot", matching what it already meant inside pattern; it previously resolved as an item id and reported a missing texture - assets/items/*.png is no longer gitignored, since that directory now only holds intentional overrides that should be committed Verified against Hugo 0.164.0: custom items resolve from the repo, vanilla items from the wiki, TNT / Flint_and_Steel / Dragon's_Breath exercise the alias and connector rules, hand-placed textures win over both, a typo fails the build, and a cold cache with no network degrades to placeholders while a warm cache builds fully offline. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
47 lines
1.6 KiB
YAML
47 lines
1.6 KiB
YAML
baseURL: https://sfclub.cc/~sfcraft
|
|
locale: zh-CN
|
|
defaultContentLanguage: zh
|
|
title: SFCraft 文档
|
|
theme: hugo-book
|
|
|
|
module:
|
|
hugoVersion:
|
|
# layouts/_partials 与 layouts/_shortcodes 目录需要 0.146+,
|
|
# 贴图解析用到的 try 需要 0.141+, hugo.Data 需要 0.156+
|
|
min: 0.156.0
|
|
|
|
params:
|
|
BookTheme: auto # 明/暗跟随系统
|
|
BookSection: '*' # 每个顶层 section 渲染为侧边栏一个栏目
|
|
BookToC: true
|
|
BookSearch: true
|
|
|
|
# crafting 组件的物品贴图解析, 见 layouts/_partials/sfcraft/item-texture.html
|
|
itemTextures:
|
|
localDir: items # 手动放置贴图的目录 (assets/<localDir>/<id>.png)
|
|
publishDir: sfc/items # 贴图发布到站点内的路径
|
|
userAgent: sfcraft-docs (+https://github.com/saltedfishclub/sfcraft-docs)
|
|
onMissing: error # 贴图确实不存在时: error 阻断构建 / warn 仅告警 / ignore 静默
|
|
repo:
|
|
enable: true
|
|
# sfcraft 自定义物品贴图; 换版本时改这里的 ref 即可
|
|
baseURL: https://raw.githubusercontent.com/saltedfishclub/sfcraft/rev/26.2/src/main/resources/assets/sfcraft/textures/item/
|
|
wiki:
|
|
enable: true
|
|
api: https://zh.minecraft.wiki/api.php
|
|
|
|
# 远程贴图与 wiki 查询的抓取缓存: 永不过期, 落在 cacheDir 下。
|
|
# 首次构建后即可离线构建; 需要拉取上游更新时执行 hugo --ignoreCache。
|
|
caches:
|
|
getresource:
|
|
dir: :cacheDir/:project
|
|
maxAge: -1
|
|
|
|
markup:
|
|
goldmark:
|
|
renderer:
|
|
unsafe: true # hugo-book 与 hugo-admonitions 均需要
|
|
tableOfContents:
|
|
startLevel: 1
|
|
endLevel: 3
|