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>
54 lines
2.0 KiB
HTML
54 lines
2.0 KiB
HTML
{{- /* 合成表中的一个格子
|
|
|
|
入参:
|
|
val 格子内容, "物品id" 或 "物品id:数量", 空字符串表示空格子
|
|
cls "grid" (九宫格) 或 "out" (输出格)
|
|
x, y 在合成表底图上的定位
|
|
page 所在页面, 仅用于报错定位
|
|
*/ -}}
|
|
|
|
{{- $val := .val -}}
|
|
{{- $item := "" -}}
|
|
{{- $count := 0 -}}
|
|
{{- if $val -}}
|
|
{{- $parts := split $val ":" -}}
|
|
{{- $item = index $parts 0 -}}
|
|
{{- if gt (len $parts) 1 -}}
|
|
{{- $count = int (index $parts 1) -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
{{- $img := false -}}
|
|
{{- if $item -}}
|
|
{{- /* 以 id 为 key, 同一物品每次构建只解析一次 */ -}}
|
|
{{- $texture := partialCached "sfcraft/item-texture.html" (dict "id" $item) $item -}}
|
|
{{- $img = $texture.image -}}
|
|
|
|
{{- if ne $texture.status "ok" -}}
|
|
{{- $where := printf "%s 引用的物品 %q" .page.Path $item -}}
|
|
{{- $onMissing := (site.Params.itemTextures | default dict).onMissing | default "error" -}}
|
|
{{- if eq $texture.status "degraded" -}}
|
|
{{- /* 离线 / 限流 / 上游异常: 结论不可靠, 只告警, 不阻断构建 */ -}}
|
|
{{- warnf "%s 贴图解析失败, 已降级为占位符: %s" $where $texture.detail -}}
|
|
{{- else if eq $onMissing "error" -}}
|
|
{{- errorf "%s 没有对应贴图。请检查 id 拼写, 或把贴图放进 assets/items/%s.png" $where $item -}}
|
|
{{- else if eq $onMissing "warn" -}}
|
|
{{- warnf "%s 没有对应贴图" $where -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
|
|
<div class="sfc-slot sfc-{{ .cls }}"
|
|
style="left: {{ .x }}; top: {{ .y }};"
|
|
{{ with $item }}data-name="{{ . }}"{{ end }}>
|
|
{{- if $img -}}
|
|
<img class="sfc-item" src="{{ $img.RelPermalink }}"
|
|
alt="{{ $item }}" width="{{ $img.Width }}" height="{{ $img.Height }}" loading="lazy">
|
|
{{- if gt $count 1 -}}
|
|
<span class="sfc-count">{{ $count }}</span>
|
|
{{- end -}}
|
|
{{- else if $item -}}
|
|
<span class="sfc-missing" title="未找到物品 {{ $item }} 的贴图">?</span>
|
|
{{- end -}}
|
|
</div>
|