Skip to content

Commit

Permalink
feat(route): Mirror Media (#16069)
Browse files Browse the repository at this point in the history
* feat(route): Mirror Media

* .
  • Loading branch information
dzx-dzx committed Jul 2, 2024
1 parent 13c1eb0 commit 446aab6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
56 changes: 56 additions & 0 deletions lib/routes/mirrormedia/index.ts
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,
};
}
6 changes: 6 additions & 0 deletions lib/routes/mirrormedia/namespace.ts
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',
};

0 comments on commit 446aab6

Please sign in to comment.