fix(route/apnews): Remove duplicate (#15966)

This commit is contained in:
Andvari
2024-06-22 21:51:43 +08:00
committed by GitHub
parent 8979027ce5
commit c0638543b7
2 changed files with 6 additions and 2 deletions
+2 -2
View File
@@ -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'),
};
}
+4
View File
@@ -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);