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>
118 lines
2.2 KiB
CSS
118 lines
2.2 KiB
CSS
.sfc-crafting {
|
|
position: relative;
|
|
width: 100%;
|
|
max-width: 540px;
|
|
aspect-ratio: 320 / 160;
|
|
margin: 1rem 0 1.25rem;
|
|
background-repeat: no-repeat;
|
|
background-size: 100% 100%;
|
|
container-type: inline-size;
|
|
}
|
|
|
|
.sfc-slot {
|
|
position: absolute;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.sfc-grid {
|
|
width: 10.625%;
|
|
height: 21.25%;
|
|
}
|
|
|
|
.sfc-out {
|
|
width: 15.625%;
|
|
height: 31.25%;
|
|
}
|
|
|
|
.sfc-item {
|
|
width: 88%;
|
|
height: 88%;
|
|
object-fit: contain;
|
|
image-rendering: pixelated;
|
|
filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
|
|
}
|
|
|
|
.sfc-count {
|
|
position: absolute;
|
|
right: 5%;
|
|
bottom: 3%;
|
|
font-family: "Minecraft", ui-monospace, Consolas, monospace;
|
|
font-size: 12px;
|
|
font-size: 2.8cqw;
|
|
font-weight: 700;
|
|
line-height: 1;
|
|
color: #fff;
|
|
text-shadow:
|
|
0 1px 0 #3f3f3f,
|
|
1px 0 0 #3f3f3f,
|
|
0 -1px 0 #3f3f3f,
|
|
-1px 0 0 #3f3f3f,
|
|
0 2px 3px rgba(0, 0, 0, 0.55);
|
|
}
|
|
|
|
/* 贴图缺失时的占位符 */
|
|
.sfc-missing {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
width: 86%;
|
|
height: 86%;
|
|
font-size: 4cqw;
|
|
font-weight: 700;
|
|
color: rgba(0, 0, 0, 0.28);
|
|
border: 2px dashed rgba(0, 0, 0, 0.18);
|
|
border-radius: 4px;
|
|
background: repeating-linear-gradient(
|
|
45deg,
|
|
rgba(255, 255, 255, 0.22),
|
|
rgba(255, 255, 255, 0.22) 4px,
|
|
rgba(0, 0, 0, 0.04) 4px,
|
|
rgba(0, 0, 0, 0.04) 8px
|
|
);
|
|
}
|
|
|
|
/* 悬停显示物品 id */
|
|
.sfc-slot[data-name]::after {
|
|
content: attr(data-name);
|
|
position: absolute;
|
|
bottom: calc(100% + 6px);
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
padding: 3px 9px;
|
|
border: 1px solid rgba(255, 255, 255, 0.16);
|
|
border-radius: 5px;
|
|
background: rgba(18, 18, 18, 0.92);
|
|
color: #fff;
|
|
font-size: 12px;
|
|
white-space: nowrap;
|
|
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
|
|
opacity: 0;
|
|
pointer-events: none;
|
|
transition: opacity 0.12s ease;
|
|
z-index: 30;
|
|
}
|
|
|
|
.sfc-slot[data-name]:hover::after {
|
|
opacity: 1;
|
|
}
|
|
|
|
.sfc-caption {
|
|
margin: 0.35rem 0 0;
|
|
text-align: center;
|
|
font-size: 0.85rem;
|
|
color: var(--gray-600, #6c757d);
|
|
}
|
|
|
|
.sfc-error {
|
|
max-width: 540px;
|
|
margin: 1rem 0;
|
|
padding: 0.6rem 1rem;
|
|
border: 1px solid #f5c2c7;
|
|
border-radius: 6px;
|
|
background: #f8d7da;
|
|
color: #842029;
|
|
font-size: 0.9rem;
|
|
}
|