fix(route/apnews): Remove duplicate (#15966)
This commit is contained in:
@@ -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'),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user