Commit 5cdadaef authored by 谢宇轩's avatar 谢宇轩

fix: edit registry filter

parent b8bcd696
......@@ -125,6 +125,11 @@ function originalFilename(titleEn, sourceName) {
// ── Registry ─────────────────────────────────────────────────────────────────
function normalizeUrl(u) {
try { const p = new URL(u); p.search = ''; return p.toString(); }
catch (e) { return u; }
}
function buildDedupSet(config, sourceId) {
const seen = new Set();
const windowDays = config.registryWindowDays || 7;
......@@ -132,23 +137,38 @@ function buildDedupSet(config, sourceId) {
const source = config.sources.find(s => s.id === sourceId);
if (!source) return seen;
// vaultFolder 含 "/" 时(如 "日经亚洲/世界"),从主目录遍历所有二级子目录的 registry.json,
// 实现同主目录下不同栏目的跨栏目去重;否则只扫描自身目录。
const parts = source.vaultFolder.split('/');
let dayRoots;
if (parts.length > 1) {
const primary = path.join(vaultPath, parts[0]);
if (!fs.existsSync(primary)) return seen;
dayRoots = fs.readdirSync(primary)
.filter(sub => fs.statSync(path.join(primary, sub)).isDirectory())
.map(sub => path.join(primary, sub));
} else {
const folder = path.join(vaultPath, source.vaultFolder);
if (!fs.existsSync(folder)) return seen;
dayRoots = [folder];
}
const today = new Date();
for (let i = 0; i < windowDays; i++) {
const d = new Date(today); d.setDate(today.getDate() - i);
const dayStr = `${d.getFullYear()}${String(d.getMonth()+1).padStart(2,'0')}${String(d.getDate()).padStart(2,'0')}`;
const regPath = path.join(folder, dayStr, 'registry.json');
for (const root of dayRoots) {
const regPath = path.join(root, dayStr, 'registry.json');
if (fs.existsSync(regPath)) {
try {
const reg = JSON.parse(fs.readFileSync(regPath, 'utf8'));
(reg.articles || []).forEach(a => seen.add(a.url));
(reg.articles || []).forEach(a => seen.add(normalizeUrl(a.url)));
} catch (e) {
console.error(` ⚠️ Failed to parse registry ${regPath}: ${e.message}`);
}
}
}
}
return seen;
}
......@@ -484,7 +504,6 @@ Examples:
console.error(` Collected ${links.length} candidate links`);
// Normalize URLs (strip query params for dedup)
const normalizeUrl = (u) => { try { const p = new URL(u); p.search = ''; return p.toString(); } catch(e) { return u; } };
const normalizedLinks = [...new Set(links.map(u => normalizeUrl(u)))];
// Keep ALL new candidates rather than slicing to `count`: recipe sources with
// validateArticle reject section/category pages only at fetch time, so capping
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment