Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
news-harvester
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Back End
news-harvester
Commits
5cdadaef
Commit
5cdadaef
authored
Aug 05, 2026
by
谢宇轩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: edit registry filter
parent
b8bcd696
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
10 deletions
+29
-10
harvest.js
scripts/harvest.js
+29
-10
No files found.
scripts/harvest.js
View file @
5cdadaef
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment