feat(expand): P0-P3 素材扩库批次(发现器 + Google Fonts + Poly Haven + Noto Emoji 3D)
- P0: scripts/discover-sources.js 四通道候选发现,产出 candidates.json / registry.json - P1: build-posters 新增 fontsource 适配器,接入 Google Fonts 2766 个 woff2 - P2: 新增 polyhaven 适配器,接入 Poly Haven CC0 纹理 238 张 - P3: build-icons 新增 gh-raster listPath(Git Tree 逐级下钻),接入 Noto Emoji 3D 3797 个 PNG - 修复: GitHub Contents API 不支持目录分页导致重复/截断,改为 Git Tree 下钻并按路径去重;audit-files.json 同步重建 - 判定 noto-emoji-2d / twemoji-png 与既有 Iconify 源同图重复,不予收录 - 基线: 图标 264 源/448,551;海报 69 源/5,366;版本联动 20261108a
This commit is contained in:
+237
-139
@@ -2,174 +2,272 @@
|
||||
/**
|
||||
* 画个标 · 素材源发现器
|
||||
*
|
||||
* 扫描 Iconify 官方集合清单,与本地已收录源对比,输出:
|
||||
* - 可直接新增的独立源(协议合规、非别名)
|
||||
* - 别名/子集(同库不同 id,避免重复收录)
|
||||
* - 协议不合规(BY-NC / BY-SA / BY-ND / GPL)
|
||||
* - 需人工判断(品牌/商标风险、协议不明)
|
||||
* 目标:把「找新素材源」从人工探测变成一次可重复运行的扫描,输出候选清单供准入筛选。
|
||||
*
|
||||
* 数据来源(全部公开 API,无需鉴权):
|
||||
* 1. Iconify https://api.iconify.design/collections —— 图标集合全集与差值
|
||||
* 2. Fontsource https://api.fontsource.org/v1/fonts —— Google Fonts 全字族
|
||||
* 3. Poly Haven https://api.polyhaven.com/assets?t=textures —— CC0 纹理
|
||||
* 4. GitHub https://api.github.com/search/repositories —— 主题检索(限流 10 次/分)
|
||||
*
|
||||
* 产物:
|
||||
* js/data/candidates.json 候选清单(按 score 降序)
|
||||
* js/data/sources/registry.json 源注册表(active 全量快照 + rejected 排除记录)
|
||||
*
|
||||
* 用法:
|
||||
* node scripts/discover-sources.js
|
||||
* node scripts/discover-sources.js --json # 只输出 JSON
|
||||
*
|
||||
* 输出文件:output/source-candidates.json(不入库)
|
||||
* node scripts/discover-sources.js # 扫描并写入上述两个文件
|
||||
* node scripts/discover-sources.js --dry # 只打印摘要,不写文件
|
||||
* node scripts/discover-sources.js --only=iconify,font,texture
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const https = require('https');
|
||||
|
||||
const ROOT = path.resolve(__dirname, '..');
|
||||
const OUT_DIR = path.join(ROOT, 'output');
|
||||
const SOURCES_FILE = path.join(ROOT, 'js', 'data', 'icon-sources.js');
|
||||
const ICON_SRC = path.join(ROOT, 'js', 'data', 'icon-sources.js');
|
||||
const POSTER_SRC = path.join(ROOT, 'js', 'data', 'poster-sources.js');
|
||||
const OUT_CANDIDATES = path.join(ROOT, 'js', 'data', 'candidates.json');
|
||||
const OUT_REGISTRY = path.join(ROOT, 'js', 'data', 'sources', 'registry.json');
|
||||
|
||||
/** 已知别名 / 子集:这些 Iconify id 与本地已有源是同一套图标,不应重复收录 */
|
||||
const ALIAS = {
|
||||
ph: 'phosphor',
|
||||
bi: 'bootstrap',
|
||||
bx: 'boxicons',
|
||||
ri: 'remix',
|
||||
'ant-design': 'antd',
|
||||
'radix-icons': 'radix',
|
||||
'game-icons': 'gameicons',
|
||||
'heroicons-outline': 'heroicons',
|
||||
'heroicons-solid': 'heroicons',
|
||||
'tabler-flags': 'tabler',
|
||||
fa: 'fontawesome',
|
||||
'fa-solid': 'fontawesome',
|
||||
'fa-regular': 'fontawesome',
|
||||
'fa-brands': 'fontawesome',
|
||||
'fa6-solid': 'fontawesome',
|
||||
'fa6-regular': 'fontawesome',
|
||||
'fa6-brands': 'fontawesome'
|
||||
};
|
||||
/* ---------------- 准入规则(与项目规则一致) ---------------- */
|
||||
const LICENSE_OK = /^(MIT|ISC|Apache-2\.0|Apache 2\.0|OFL-1\.1|CC0(-1\.0)?|Unlicense|BSD-3-Clause|BSD-2-Clause|MPL-2\.0)$/i;
|
||||
const LICENSE_BLOCK = /BY-SA|BY-NC|BY-ND|\bGPL\b|NonCommercial|非商业|禁止商用/i;
|
||||
|
||||
/** 已知品牌/商标风险集合(可收录但需标注,不建议用于 LOGO) */
|
||||
const BRAND_RISK = new Set(['arcticons', 'wordpress', 'brandico', 'entypo-social', 'fa6-brands']);
|
||||
/** 已知排除项(协议/可拉取性/同质重复),避免每轮重复踩坑 */
|
||||
const REJECTED = [
|
||||
{ id: 'undraw', kind: 'poster', reason: '自定义协议禁止 AI/机器学习训练,与 AI 海报生成冲突' },
|
||||
{ id: 'open-doodles', kind: 'poster', reason: 'CC0 但托管控于 Dropbox/Webflow,无可用直链仓库' },
|
||||
{ id: 'hero-patterns', kind: 'poster', reason: '仓库无 LICENSE 文件,合规风险' },
|
||||
{ id: 'arcticons', kind: 'icon', reason: 'CC BY-SA 4.0 传染性协议,不可商用收录' },
|
||||
{ id: 'openmoji', kind: 'icon', reason: 'CC BY-SA 4.0 传染性协议(已通过 iconify 收录的源需复查)' },
|
||||
{ id: '3dicons', kind: 'icon', reason: '仓库是站点源码,无批量静态素材(仅 12 张示例图)' },
|
||||
{ id: 'svgwave', kind: 'poster', reason: '运行时生成器,无静态 SVG 产物' },
|
||||
{ id: 'inkjet', kind: 'poster', reason: '运行时生成器,无静态 SVG 产物' },
|
||||
{ id: 'mrmrs-patterns', kind: 'poster', reason: 'jsDelivr 未索引,无法直拉' },
|
||||
{ id: 'dracula', kind: 'poster', reason: '主题色存于扩展仓库,主仓库无配色 JSON' },
|
||||
{ id: 'montserrat', kind: 'poster', reason: '仓库体积超 jsDelivr 索引上限' },
|
||||
{ id: 'noto-emoji-repo', kind: 'icon', reason: '1.4GB 仓库,整树枚举不稳定;改用 GitHub Trees API 分目录(P3 已用子树方式接入)' }
|
||||
];
|
||||
|
||||
function fetchJson(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
https.get(url, { headers: { 'User-Agent': 'drawlogo-source-discovery' } }, res => {
|
||||
let data = '';
|
||||
res.on('data', c => { data += c; });
|
||||
res.on('end', () => {
|
||||
try { resolve(JSON.parse(data)); }
|
||||
catch (e) { reject(new Error('解析失败: ' + url)); }
|
||||
});
|
||||
}).on('error', reject);
|
||||
});
|
||||
function readSources(file) {
|
||||
if (!fs.existsSync(file)) return [];
|
||||
delete require.cache[require.resolve(file)];
|
||||
const list = require(file);
|
||||
return Array.isArray(list) ? list : [];
|
||||
}
|
||||
|
||||
function readExistingIds() {
|
||||
const text = fs.readFileSync(SOURCES_FILE, 'utf8');
|
||||
return new Set([...text.matchAll(/\bid:\s*'([^']+)'/g)].map(m => m[1]));
|
||||
async function getJSON(url, headers) {
|
||||
const r = await fetch(url, { headers: Object.assign({ 'User-Agent': 'drawlogo-discover' }, headers || {}) });
|
||||
if (!r.ok) throw new Error(url + ' → HTTP ' + r.status);
|
||||
return r.json();
|
||||
}
|
||||
|
||||
/** 协议是否允许商用(与项目规则一致) */
|
||||
function isCommercial(spdx) {
|
||||
const s = String(spdx || '');
|
||||
if (!s) return false;
|
||||
return !/(^|[\s-])(NC|SA|ND)([\s-]|$)|NonCommercial|GPL/i.test(s);
|
||||
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
||||
|
||||
/* ---------------- 1. Iconify ---------------- */
|
||||
async function scanIconify(iconSources) {
|
||||
const used = new Set();
|
||||
for (const s of iconSources) {
|
||||
used.add(s.id);
|
||||
if (s.npm) {
|
||||
const m = String(s.npm).match(/@iconify-json\/([^@/\s]+)/);
|
||||
if (m) used.add(m[1]);
|
||||
}
|
||||
}
|
||||
const all = await getJSON('https://api.iconify.design/collections');
|
||||
const out = [];
|
||||
for (const [prefix, v] of Object.entries(all)) {
|
||||
const aliases = v.aliases || [];
|
||||
if (used.has(prefix) || aliases.some(a => used.has(a))) continue;
|
||||
const license = (v.license && (v.license.spdx || v.license.title)) || '?';
|
||||
out.push({
|
||||
kind: 'icon',
|
||||
provider: 'iconify',
|
||||
id: prefix,
|
||||
name: v.name || prefix,
|
||||
volume: v.total || 0,
|
||||
license,
|
||||
licenseOk: LICENSE_OK.test(license) && !LICENSE_BLOCK.test(license),
|
||||
category: v.category || '',
|
||||
url: 'https://icon-sets.iconify.design/' + prefix + '/',
|
||||
note: 'Iconify 集合,可直接用 format:iconify 接入'
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function pad(s, n) {
|
||||
s = String(s);
|
||||
// 中文按 2 字符宽估算
|
||||
let width = 0;
|
||||
for (const ch of s) width += /[\u4e00-\u9fa5]/.test(ch) ? 2 : 1;
|
||||
return s + ' '.repeat(Math.max(0, n - width));
|
||||
/* ---------------- 2. Fontsource(Google Fonts) ---------------- */
|
||||
async function scanFontsource(posterSources) {
|
||||
const fonts = await getJSON('https://api.fontsource.org/v1/fonts');
|
||||
const usedIds = new Set(posterSources.filter(s => s.type === 'font').map(s => s.id));
|
||||
const out = [];
|
||||
for (const f of fonts) {
|
||||
if (!LICENSE_OK.test(f.license || '') || LICENSE_BLOCK.test(f.license || '')) continue;
|
||||
if (!Array.isArray(f.subsets) || !f.subsets.includes('latin')) continue;
|
||||
// 已收录的字体源(fontsource-xxx / noto-xxx)跳过
|
||||
if (usedIds.has('fontsource-' + f.id)) continue;
|
||||
const weights = (f.weights || []).filter(w => w === 400 || w === 700);
|
||||
out.push({
|
||||
kind: 'poster',
|
||||
provider: 'fontsource',
|
||||
id: f.id,
|
||||
name: f.family,
|
||||
volume: Math.max(1, weights.length),
|
||||
license: f.license,
|
||||
licenseOk: true,
|
||||
category: 'font',
|
||||
url: 'https://fontsource.org/fonts/' + f.id,
|
||||
note: weights.length ? 'latin ' + weights.join('/') + ' 可用' : '缺 400/700 标准字重'
|
||||
});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ---------------- 3. Poly Haven 纹理 ---------------- */
|
||||
async function scanPolyhaven(posterSources) {
|
||||
const used = new Set(posterSources.map(s => s.id));
|
||||
if (used.has('polyhaven-textures')) return [];
|
||||
const all = await getJSON('https://api.polyhaven.com/assets?t=textures');
|
||||
const cats = {};
|
||||
for (const id of Object.keys(all)) {
|
||||
for (const c of (all[id].categories || [])) cats[c] = (cats[c] || 0) + 1;
|
||||
}
|
||||
const top = Object.entries(cats).sort((a, b) => b[1] - a[1]).slice(0, 8)
|
||||
.map(([c, n]) => c + '(' + n + ')').join('、');
|
||||
return [{
|
||||
kind: 'poster',
|
||||
provider: 'polyhaven',
|
||||
id: 'polyhaven-textures',
|
||||
name: 'Poly Haven Textures',
|
||||
volume: Object.keys(all).length,
|
||||
license: 'CC0-1.0',
|
||||
licenseOk: true,
|
||||
category: 'bg',
|
||||
url: 'https://polyhaven.com/textures',
|
||||
note: 'CC0 可商用免署名;分类:' + top
|
||||
}];
|
||||
}
|
||||
|
||||
/* ---------------- 4. GitHub 主题检索 ---------------- */
|
||||
async function scanGithub() {
|
||||
const topics = [
|
||||
'topic:icon-set license:mit',
|
||||
'topic:3d-icons license:mit',
|
||||
'topic:emoji license:mit',
|
||||
'topic:texture cc0-1.0'
|
||||
];
|
||||
const out = [];
|
||||
for (const q of topics) {
|
||||
try {
|
||||
const j = await getJSON('https://api.github.com/search/repositories?q=' + encodeURIComponent(q) +
|
||||
'&sort=stars&order=desc&per_page=10', { Accept: 'application/vnd.github+json' });
|
||||
for (const r of (j.items || [])) {
|
||||
const license = (r.license && r.license.spdx_id) || '?';
|
||||
out.push({
|
||||
kind: q.includes('texture') ? 'poster' : 'icon',
|
||||
provider: 'github',
|
||||
id: r.full_name.replace('/', '-').toLowerCase(),
|
||||
name: r.full_name,
|
||||
volume: r.stargazers_count,
|
||||
license,
|
||||
licenseOk: LICENSE_OK.test(license),
|
||||
category: r.topics && r.topics.slice(0, 3).join(',') || '',
|
||||
url: r.html_url,
|
||||
note: '★' + r.stargazers_count + ' · 仓库 ' + Math.round(r.size / 1024) + 'MB(volume 为星数,需人工确认素材量)'
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(' ⚠️ GitHub 检索失败(' + q + '):' + e.message);
|
||||
}
|
||||
await sleep(6500); // 未鉴权搜索接口限流 10 次/分钟
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ---------------- 评分与输出 ---------------- */
|
||||
function score(c) {
|
||||
if (!c.licenseOk) return 0;
|
||||
const vol = Math.min(c.volume, 50000) / 50000;
|
||||
const kindWeight = c.kind === 'icon' ? 1 : 1.1;
|
||||
return +(vol * 60 * kindWeight + 40).toFixed(1);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('画个标 · 素材源发现器\n');
|
||||
const dry = process.argv.includes('--dry');
|
||||
const onlyArg = (process.argv.find(a => a.startsWith('--only=')) || '').replace('--only=', '');
|
||||
const only = onlyArg ? new Set(onlyArg.split(',')) : null;
|
||||
|
||||
const existing = readExistingIds();
|
||||
console.log(`本地已收录源: ${existing.size}`);
|
||||
const iconSources = readSources(ICON_SRC);
|
||||
const posterSources = readSources(POSTER_SRC);
|
||||
console.log(`已收录:图标源 ${iconSources.length},海报源 ${posterSources.length}`);
|
||||
|
||||
const collections = await fetchJson('https://api.iconify.design/collections');
|
||||
const allIds = Object.keys(collections);
|
||||
console.log(`Iconify 官方集合: ${allIds.length}\n`);
|
||||
|
||||
const covered = [];
|
||||
const candidates = [];
|
||||
const aliases = [];
|
||||
const nonCommercial = [];
|
||||
|
||||
for (const id of allIds) {
|
||||
const info = collections[id] || {};
|
||||
const item = {
|
||||
id,
|
||||
name: info.name || id,
|
||||
total: info.total || 0,
|
||||
license: (info.license && info.license.spdx) || (info.license && info.license.title) || '未知',
|
||||
author: info.author && info.author.name ? info.author.name : '',
|
||||
home: info.author && info.author.url ? info.author.url : '',
|
||||
brandRisk: BRAND_RISK.has(id)
|
||||
};
|
||||
|
||||
if (existing.has(id)) { covered.push(item); continue; }
|
||||
if (ALIAS[id]) { aliases.push({ ...item, aliasOf: ALIAS[id] }); continue; }
|
||||
if (!isCommercial(item.license)) { nonCommercial.push(item); continue; }
|
||||
|
||||
// 预判拉取方式:Iconify 集合统一走 npm @iconify-json/<id> + format:'iconify' + scaleMode:'body'
|
||||
item.suggestConfig = {
|
||||
format: 'iconify',
|
||||
npm: '@iconify-json/' + id,
|
||||
scaleMode: 'body',
|
||||
type: item.brandRisk ? 'brand' : 'icon'
|
||||
};
|
||||
candidates.push(item);
|
||||
const tasks = [
|
||||
['iconify', () => scanIconify(iconSources)],
|
||||
['font', () => scanFontsource(posterSources)],
|
||||
['texture', () => scanPolyhaven(posterSources)],
|
||||
['github', () => scanGithub()]
|
||||
];
|
||||
for (const [key, fn] of tasks) {
|
||||
if (only && !only.has(key)) continue;
|
||||
try {
|
||||
const list = await fn();
|
||||
console.log(`扫描 ${key}: ${list.length} 个候选`);
|
||||
candidates.push(...list);
|
||||
} catch (e) {
|
||||
console.warn(`扫描 ${key} 失败:${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
candidates.sort((a, b) => b.total - a.total);
|
||||
for (const c of candidates) c.score = score(c);
|
||||
candidates.sort((a, b) => b.score - a.score || b.volume - a.volume);
|
||||
|
||||
if (process.argv.includes('--json')) {
|
||||
console.log(JSON.stringify({ candidates, aliases, nonCommercial }, null, 2));
|
||||
const ok = candidates.filter(c => c.licenseOk);
|
||||
const blocked = candidates.filter(c => !c.licenseOk);
|
||||
|
||||
// 注册表:active 全量快照 + rejected 记录
|
||||
const registry = {
|
||||
updatedAt: new Date().toISOString().slice(0, 10),
|
||||
iconSources: {},
|
||||
posterSources: {},
|
||||
rejected: REJECTED
|
||||
};
|
||||
for (const s of iconSources) {
|
||||
registry.iconSources[s.id] = {
|
||||
format: s.format || '', license: s.license || '', type: s.type || '', added: s.added || ''
|
||||
};
|
||||
}
|
||||
for (const s of posterSources) {
|
||||
registry.posterSources[s.id] = {
|
||||
format: s.format || '', license: s.license || '', type: s.type || '', added: s.added || ''
|
||||
};
|
||||
}
|
||||
|
||||
console.log(`\n可用候选 ${ok.length} 个(占比 ${(ok.length / Math.max(1, candidates.length) * 100).toFixed(0)}%),` +
|
||||
`协议不合规 ${blocked.length} 个已排除`);
|
||||
console.log('Top 10:');
|
||||
for (const c of ok.slice(0, 10)) {
|
||||
console.log(` ${String(c.score).padStart(5)} ${c.provider.padEnd(11)} ${c.id.padEnd(28)} ` +
|
||||
`${String(c.volume).padStart(6)} ${c.license}`);
|
||||
}
|
||||
const byProvider = {};
|
||||
for (const c of ok) byProvider[c.provider] = (byProvider[c.provider] || 0) + 1;
|
||||
console.log('候选分布:' + JSON.stringify(byProvider));
|
||||
|
||||
if (dry) {
|
||||
console.log('\n--dry 模式,未写文件');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('=== 可直接新增(协议合规、非别名)===');
|
||||
console.log(pad('ID', 22) + pad('图标数', 9) + pad('协议', 18) + pad('品牌风险', 10) + '名称');
|
||||
console.log('-'.repeat(100));
|
||||
for (const c of candidates) {
|
||||
console.log(
|
||||
pad(c.id, 22) +
|
||||
pad(c.total.toLocaleString('zh-CN'), 9) +
|
||||
pad(c.license, 18) +
|
||||
pad(c.brandRisk ? '是' : '-', 10) +
|
||||
c.name
|
||||
);
|
||||
}
|
||||
|
||||
console.log('\n=== 别名 / 子集(跳过,避免重复)===');
|
||||
console.log(aliases.map(a => `${a.id} → ${a.aliasOf}`).join(', ') || '无');
|
||||
|
||||
console.log('\n=== 协议不合规(跳过)===');
|
||||
console.log(nonCommercial.map(a => `${a.id}(${a.license})`).join(', ') || '无');
|
||||
|
||||
const totalIcons = candidates.reduce((a, b) => a + b.total, 0);
|
||||
console.log('\n=== 汇总 ===');
|
||||
console.log(`已覆盖: ${covered.length}`);
|
||||
console.log(`可新增独立源: ${candidates.length} 个,约 ${totalIcons.toLocaleString('zh-CN')} 个图标`);
|
||||
console.log(`其中品牌风险: ${candidates.filter(c => c.brandRisk).length} 个`);
|
||||
console.log(`别名/子集: ${aliases.length} 个`);
|
||||
console.log(`协议不合规: ${nonCommercial.length} 个`);
|
||||
|
||||
fs.mkdirSync(OUT_DIR, { recursive: true });
|
||||
const outFile = path.join(OUT_DIR, 'source-candidates.json');
|
||||
fs.writeFileSync(outFile, JSON.stringify({
|
||||
scannedAt: new Date().toISOString(),
|
||||
iconifyTotal: allIds.length,
|
||||
covered: covered.length,
|
||||
candidates,
|
||||
aliases,
|
||||
nonCommercial
|
||||
}, null, 2));
|
||||
console.log(`\n候选清单已写入: ${path.relative(ROOT, outFile)}`);
|
||||
fs.mkdirSync(path.dirname(OUT_REGISTRY), { recursive: true });
|
||||
fs.writeFileSync(OUT_CANDIDATES, JSON.stringify({
|
||||
generatedAt: new Date().toISOString(),
|
||||
total: candidates.length,
|
||||
candidates
|
||||
}, null, 2) + '\n', 'utf8');
|
||||
fs.writeFileSync(OUT_REGISTRY, JSON.stringify(registry, null, 2) + '\n', 'utf8');
|
||||
console.log('\n已写入:' + path.relative(ROOT, OUT_CANDIDATES) + '、' + path.relative(ROOT, OUT_REGISTRY));
|
||||
}
|
||||
|
||||
main().catch(e => {
|
||||
console.error('发现失败:', e.message);
|
||||
process.exit(1);
|
||||
});
|
||||
main().catch(e => { console.error('❌ 发现器失败:' + e.message); process.exit(1); });
|
||||
|
||||
Reference in New Issue
Block a user