-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route/yicai): Add route for carousel part on front page (#16433)
* feat(route/yicai): Add route for carousel part on front page * . * . * . * . * . * ...ESLint...
- Loading branch information
Showing
2 changed files
with
71 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Route } from '@/types'; | ||
import cache from '@/utils/cache'; | ||
import { rootUrl, fetchFullArticles } from './utils'; | ||
import ofetch from '@/utils/ofetch'; | ||
import { load } from 'cheerio'; | ||
|
||
export const route: Route = { | ||
path: '/carousel', | ||
categories: ['traditional-media'], | ||
example: '/yicai/carousel', | ||
parameters: {}, | ||
features: { | ||
requireConfig: false, | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
radar: [ | ||
{ | ||
source: ['yicai.com/'], | ||
}, | ||
], | ||
name: '轮播', | ||
maintainers: ['nczitzk'], | ||
handler, | ||
url: 'yicai.com/', | ||
}; | ||
|
||
async function handler() { | ||
const res = await ofetch(rootUrl); | ||
const $ = load(res); | ||
const items = await Promise.all( | ||
fetchFullArticles( | ||
$('#breaknews a') | ||
.toArray() | ||
.map((e) => ({ link: new URL($(e).attr('href'), rootUrl).href, title: $(e).text() })), | ||
cache.tryGet | ||
) | ||
); | ||
|
||
return { | ||
title: '第一财经 - 轮播', | ||
link: rootUrl, | ||
item: items, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters