feat(posters): 新增图案/纹理源 pattern.css(48) 与 Radix Colors(288 色),海报库达 2358/65
This commit is contained in:
@@ -309,6 +309,43 @@ async function downloadDirFiles(src) {
|
||||
return { items, ok, fail };
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地源:读取 js/data/posters/{id}/files 下预先生成的素材(不联网)
|
||||
* 用于从 CSS 提取的图案、渐变与配色 JSON 等无独立文件的开源资源
|
||||
*/
|
||||
async function readLocalFiles(src) {
|
||||
const items = [];
|
||||
let ok = 0, fail = 0;
|
||||
const ROOT = path.join(__dirname, '..');
|
||||
const exts = (Array.isArray(src.ext) ? src.ext : (src.ext ? String(src.ext).split(',') : ['.svg']))
|
||||
.map(e => e.trim().toLowerCase());
|
||||
const dir = path.join(ROOT, 'js', 'data', 'posters', src.id, 'files');
|
||||
if (!fs.existsSync(dir)) throw new Error('本地目录不存在: ' + dir);
|
||||
const walk = (d, prefix) => {
|
||||
let out = [];
|
||||
for (const f of fs.readdirSync(d, { withFileTypes: true })) {
|
||||
if (f.isDirectory()) out = out.concat(walk(path.join(d, f.name), prefix + f.name + '/'));
|
||||
else if (exts.some(e => f.name.toLowerCase().endsWith(e))) out.push(prefix + f.name);
|
||||
}
|
||||
return out;
|
||||
};
|
||||
let picked = walk(dir, '');
|
||||
picked = dropNonAssets(picked);
|
||||
if (src.exclude) picked = picked.filter(p => !new RegExp(src.exclude).test(p));
|
||||
const cap = Number(src.maxItems) > 0 ? Math.min(Number(src.maxItems), picked.length) : picked.length;
|
||||
picked = picked.slice(0, cap);
|
||||
for (const p of picked) {
|
||||
try {
|
||||
const buf = fs.readFileSync(path.join(dir, p));
|
||||
const name = path.basename(p, path.extname(p));
|
||||
const c = classifyPoster(name);
|
||||
const it = await buildItem(src, name, 'posters/' + src.id + '/files/' + p, buf, c);
|
||||
if (it) { items.push(it); ok++; } else fail++;
|
||||
} catch (e) { fail++; }
|
||||
}
|
||||
return { items, ok, fail };
|
||||
}
|
||||
|
||||
/**
|
||||
* hero-patterns 专用转换:ES module 函数模板 → 静态 SVG 字符串
|
||||
* 源码形如:
|
||||
@@ -487,6 +524,11 @@ async function main() {
|
||||
const r = await downloadDirFiles(src);
|
||||
items = r.items; fail = r.fail; expected = r.ok + r.fail;
|
||||
usedUrl = 'unpkg.com/' + src.npm;
|
||||
} else if (src.format === 'local') {
|
||||
console.log(`读取 ${src.name}(本地预生成 ${src.id})…`);
|
||||
const r = await readLocalFiles(src);
|
||||
items = r.items; fail = r.fail; expected = r.ok + r.fail;
|
||||
usedUrl = 'local';
|
||||
} else {
|
||||
throw new Error(`不支持的 format: ${src.format}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user