-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(route): Mirror Media * .
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 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,56 @@ | ||
import { Route } from '@/types'; | ||
|
||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import cache from '@/utils/cache'; | ||
import ofetch from '@/utils/ofetch'; | ||
|
||
export const route: Route = { | ||
path: '/', | ||
categories: ['traditional-media'], | ||
example: '/mirrormedia', | ||
parameters: {}, | ||
name: '首页', | ||
maintainers: ['dzx-dzx'], | ||
radar: [ | ||
{ | ||
source: ['mirrormedia.mg'], | ||
}, | ||
], | ||
handler, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const rootUrl = 'https://www.mirrormedia.mg'; | ||
|
||
const response = await ofetch('https://v3-statics.mirrormedia.mg/files/json/post_external01.json'); | ||
|
||
const items = [...response.choices.map((e) => ({ __from: 'choices', ...e })), ...response.latest.map((e) => ({ __from: 'latest', ...e }))] | ||
.map((e) => ({ | ||
title: e.title, | ||
pubDate: parseDate(e.publishDate), | ||
category: [...(e.sections ?? []).map((_) => _.name), e.__from], | ||
link: `${rootUrl}/${e.style === '' ? 'external' : 'story'}/${e.slug}`, | ||
})) | ||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20); | ||
|
||
const list = await Promise.all( | ||
items.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const detailResponse = await ofetch(item.link); | ||
|
||
const content = load(detailResponse); | ||
|
||
item.description = content("div[data-contents='true']").html(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: '鏡週刊 Mirror Media', | ||
link: rootUrl, | ||
item: list, | ||
}; | ||
} |
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,6 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: '鏡週刊 Mirror Media', | ||
url: 'mirrormedia.mg', | ||
}; |