diff --git a/lib/routes/apnews/topics.ts b/lib/routes/apnews/topics.ts index 283c8e083..dc211d732 100644 --- a/lib/routes/apnews/topics.ts +++ b/lib/routes/apnews/topics.ts @@ -1,7 +1,7 @@ import { Route } from '@/types'; import got from '@/utils/got'; import { load } from 'cheerio'; -import { fetchArticle } from './utils'; +import { fetchArticle, removeDuplicateByKey } from './utils'; const HOME_PAGE = 'https://apnews.com'; export const route: Route = { @@ -50,7 +50,7 @@ async function handler(ctx) { title: $('title').text(), description: $("meta[property='og:description']").text(), link: url, - item: items, + item: removeDuplicateByKey(items, 'guid'), language: $('html').attr('lang'), }; } diff --git a/lib/routes/apnews/utils.ts b/lib/routes/apnews/utils.ts index a6c239223..c8b10545e 100644 --- a/lib/routes/apnews/utils.ts +++ b/lib/routes/apnews/utils.ts @@ -3,6 +3,10 @@ import ofetch from '@/utils/ofetch'; import { parseDate } from '@/utils/parse-date'; import { load } from 'cheerio'; +export function removeDuplicateByKey(items, key: string) { + return [...new Map(items.map((x) => [x[key], x])).values()]; +} + export function fetchArticle(item) { return cache.tryGet(item.link, async () => { const data = await ofetch(item.link);