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

fix: edit registry filter

parent b8bcd696
...@@ -125,6 +125,11 @@ function originalFilename(titleEn, sourceName) { ...@@ -125,6 +125,11 @@ function originalFilename(titleEn, sourceName) {
// ── Registry ───────────────────────────────────────────────────────────────── // ── Registry ─────────────────────────────────────────────────────────────────
function normalizeUrl(u) {
try { const p = new URL(u); p.search = ''; return p.toString(); }
catch (e) { return u; }
}
function buildDedupSet(config, sourceId) { function buildDedupSet(config, sourceId) {
const seen = new Set(); const seen = new Set();
const windowDays = config.registryWindowDays || 7; const windowDays = config.registryWindowDays || 7;
...@@ -132,20 +137,35 @@ function buildDedupSet(config, sourceId) { ...@@ -132,20 +137,35 @@ function buildDedupSet(config, sourceId) {
const source = config.sources.find(s => s.id === sourceId); const source = config.sources.find(s => s.id === sourceId);
if (!source) return seen; if (!source) return seen;
const folder = path.join(vaultPath, source.vaultFolder); // vaultFolder 含 "/" 时(如 "日经亚洲/世界"),从主目录遍历所有二级子目录的 registry.json,
if (!fs.existsSync(folder)) return seen; // 实现同主目录下不同栏目的跨栏目去重;否则只扫描自身目录。
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(); const today = new Date();
for (let i = 0; i < windowDays; i++) { for (let i = 0; i < windowDays; i++) {
const d = new Date(today); d.setDate(today.getDate() - 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 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) {
if (fs.existsSync(regPath)) { const regPath = path.join(root, dayStr, 'registry.json');
try { if (fs.existsSync(regPath)) {
const reg = JSON.parse(fs.readFileSync(regPath, 'utf8')); try {
(reg.articles || []).forEach(a => seen.add(a.url)); const reg = JSON.parse(fs.readFileSync(regPath, 'utf8'));
} catch (e) { (reg.articles || []).forEach(a => seen.add(normalizeUrl(a.url)));
console.error(` ⚠️ Failed to parse registry ${regPath}: ${e.message}`); } catch (e) {
console.error(` ⚠️ Failed to parse registry ${regPath}: ${e.message}`);
}
} }
} }
} }
...@@ -484,7 +504,6 @@ Examples: ...@@ -484,7 +504,6 @@ Examples:
console.error(` Collected ${links.length} candidate links`); console.error(` Collected ${links.length} candidate links`);
// Normalize URLs (strip query params for dedup) // 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)))]; const normalizedLinks = [...new Set(links.map(u => normalizeUrl(u)))];
// Keep ALL new candidates rather than slicing to `count`: recipe sources with // Keep ALL new candidates rather than slicing to `count`: recipe sources with
// validateArticle reject section/category pages only at fetch time, so capping // 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