Update public-api.js via upload script - 2026-10-28 09:36:42
This commit is contained in:
parent
1ea79f5ff5
commit
171d6f6f77
|
|
@ -230,12 +230,18 @@ function htmlSegments(h) {
|
|||
const tplHtmlOf = (t) => (t && String(t.html || '').trim() ? cleanTplHtml(t.html) : '');
|
||||
// 详情图片里的 HTML 片段(原样显示,网站上放在隔离的 iframe 里):detailHtml = [{ id, html, pos }],pos = 排在第几张图后面(0 = 最上面)
|
||||
const tplDetailBlocks = (t) => arr(t && t.detailHtml).filter((b) => b && String(b.html || '').trim());
|
||||
function tplDetailSeq(t) {
|
||||
const imgs = tplImagesOf(t), blocks = tplDetailBlocks(t);
|
||||
// 同一模板下给某个型号去掉部分内容:modelExclude = { 产品id: { images: [文件名], blocks: [片段id], html: true } };没设置 = 全部都用
|
||||
const exclOf = (t, p) => (t && t.modelExclude && p && t.modelExclude[p.id]) || {};
|
||||
const tplImagesFor = (t, p) => { const ex = arr(exclOf(t, p).images); return tplImagesOf(t).filter((f) => !ex.includes(f)); };
|
||||
const tplBlocksFor = (t, p) => { const ex = arr(exclOf(t, p).blocks); return tplDetailBlocks(t).filter((b) => !ex.includes(b.id)); };
|
||||
const tplHtmlFor = (t, p) => (exclOf(t, p).html ? '' : tplHtmlOf(t));
|
||||
// 详情图片 + HTML 片段的顺序:片段位置按模板里的原始图片序号算,去掉的图片 / 片段跳过
|
||||
function tplDetailSeq(t, p) {
|
||||
const all = tplImagesOf(t), keep = tplImagesFor(t, p), blocks = tplBlocksFor(t, p);
|
||||
const out = [];
|
||||
for (let i = 0; i <= imgs.length; i++) {
|
||||
for (const b of blocks) if (Math.min(Math.max(0, Math.round(+b.pos || 0)), imgs.length) === i) out.push({ html: String(b.html).replace(/\s*\[cite:[^\]]*\]/gi, '') });
|
||||
if (i < imgs.length) out.push({ img: imgs[i] });
|
||||
for (let i = 0; i <= all.length; i++) {
|
||||
for (const b of blocks) if (Math.min(Math.max(0, Math.round(+b.pos || 0)), all.length) === i) out.push({ html: String(b.html).replace(/\s*\[cite:[^\]]*\]/gi, '') });
|
||||
if (i < all.length && keep.includes(all[i])) out.push({ img: all[i] });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
@ -483,17 +489,17 @@ function toPublic(p, templates = [], packSpecs = []) {
|
|||
out.images = (coverUrl ? [coverUrl, ...ownUrls, ...mainTpl.filter((u) => u !== coverUrl)] : [...ownUrls, ...mainTpl]).slice(0, 6);
|
||||
out.detailImages = detailsOf(p).map((f) => `${base}/api/public/media/${slug}/${encodeURIComponent(f)}`);
|
||||
// 模板图片:同一个模板被多个产品引用时 URL 相同,网站构建时只下载一次
|
||||
const tplUrls = templatesOf(p, templates).flatMap((t) => tplImagesOf(t)
|
||||
const tplUrls = templatesOf(p, templates).flatMap((t) => tplImagesFor(t, p)
|
||||
.map((f) => `${base}/api/public/tplmedia/${encodeURIComponent(t.id)}/${encodeURIComponent(f)}`));
|
||||
if (tplUrls.length) out.templateImages = tplUrls;
|
||||
// 有 HTML 片段时,额外给出"图片 + HTML"的完整顺序(网站按这个顺序显示;没有 HTML 片段的模板不输出,网站沿用 templateImages)
|
||||
if (templatesOf(p, templates).some((t) => tplDetailBlocks(t).length)) {
|
||||
out.templateDetail = templatesOf(p, templates).flatMap((t) => tplDetailSeq(t).map((x) => (x.img
|
||||
if (templatesOf(p, templates).some((t) => tplBlocksFor(t, p).length)) {
|
||||
out.templateDetail = templatesOf(p, templates).flatMap((t) => tplDetailSeq(t, p).map((x) => (x.img
|
||||
? { img: `${base}/api/public/tplmedia/${encodeURIComponent(t.id)}/${encodeURIComponent(x.img)}` }
|
||||
: { html: { en: x.html } })));
|
||||
}
|
||||
// HTML 模板(系列参数表等):显示在详情图下方
|
||||
const tplHtml = templatesOf(p, templates).map((t) => ({ id: t.id, html: { en: tplHtmlOf(t) } })).filter((x) => x.html.en);
|
||||
const tplHtml = templatesOf(p, templates).map((t) => ({ id: t.id, html: { en: tplHtmlFor(t, p) } })).filter((x) => x.html.en);
|
||||
if (tplHtml.length) out.templateHtml = tplHtml;
|
||||
return out;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue