forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1370 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
6 changed files
with
168 additions
and
139 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,66 @@ | ||
import { Route } from '@/types'; | ||
import ofetch from '@/utils/ofetch'; | ||
|
||
import cache from '@/utils/cache'; | ||
import { load } from 'cheerio'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
|
||
export const route: Route = { | ||
path: '/:category', | ||
categories: ['new-media'], | ||
radar: [{ source: ['www.copernicium.tw'] }], | ||
name: '分类', | ||
example: '/copernicium/环球视角', | ||
parameters: { category: '分类名' }, | ||
maintainers: ['dzx-dzx'], | ||
handler, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const CATEGORY_TO_ARG_MAP = new Map([ | ||
['环球视角', '4_1'], | ||
['人文叙述', '4_3'], | ||
['观点评论', '4_5'], | ||
]); | ||
if (!CATEGORY_TO_ARG_MAP.get(ctx.req.param().category)) { | ||
throw new Error('The requested category does not exist or is not supported.'); | ||
} | ||
const reqArgs = { | ||
args: { | ||
_jcp: CATEGORY_TO_ARG_MAP.get(ctx.req.param().category), | ||
m31pageno: 1, | ||
}, | ||
type: 0, | ||
}; | ||
const res = await ofetch(`https://www.copernicium.tw/nr.jsp`, { | ||
query: { _reqArgs: reqArgs }, | ||
}); | ||
const $ = load(res); | ||
const list = $('.J_newsResultLine a.mixNewsStyleTitle') | ||
.toArray() | ||
.map((e) => { | ||
e = $(e); | ||
return { | ||
title: e.text(), | ||
link: e.attr('href'), | ||
}; | ||
}); | ||
const items = await Promise.all( | ||
list.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const detailResponse = await ofetch(item.link); | ||
const content = load(detailResponse); | ||
return { | ||
pubDate: parseDate(content('span.newsInfo').text().substring(5)), | ||
description: content('.richContent').html(), | ||
...item, | ||
}; | ||
}) | ||
) | ||
); | ||
return { | ||
title: `日新说 - ${ctx.req.param().category}`, | ||
link: 'https://www.copernicium.tw', | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: '日新说', | ||
url: 'www.copernicium.tw', | ||
}; |
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
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
export default { | ||
getItem: (note) => { | ||
let link = note.metadata?.content?.external_urls?.[0] ?? `https://crossbell.io/notes/${note.characterId}-${note.noteId}`; | ||
if (link.startsWith('https://xn--')) { | ||
link = `https://crossbell.io/notes/${note.characterId}-${note.noteId}`; | ||
} | ||
return { | ||
title: note.metadata?.content?.title || '', | ||
description: note.metadata?.content?.content, | ||
link, | ||
pubDate: note.metadata?.content?.publishedAt, | ||
updated: note.metadata?.content?.updatedAt, | ||
author: note.metadata?.content?.authors?.[0] || note.character?.metadata?.content?.name || note.character?.handle, | ||
guid: `https://crossbell.io/notes/${note.characterId}-${note.noteId}`, | ||
category: [...(note.metadata?.content?.sources || []), ...(note.metadata?.content?.tags || [])], | ||
}; | ||
}, | ||
export const getItem = (note) => { | ||
let link = note.metadata?.content?.external_urls?.[0] ?? `https://crossbell.io/notes/${note.characterId}-${note.noteId}`; | ||
if (link.startsWith('https://xn--')) { | ||
link = `https://crossbell.io/notes/${note.characterId}-${note.noteId}`; | ||
} | ||
return { | ||
title: note.metadata?.content?.title || '', | ||
description: note.metadata?.content?.content, | ||
link, | ||
pubDate: note.metadata?.content?.publishedAt, | ||
updated: note.metadata?.content?.updatedAt, | ||
author: note.metadata?.content?.authors?.[0] || note.character?.metadata?.content?.name || note.character?.handle, | ||
guid: `https://crossbell.io/notes/${note.characterId}-${note.noteId}`, | ||
category: [...(note.metadata?.content?.sources || []), ...(note.metadata?.content?.tags || [])], | ||
}; | ||
}; |
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
Oops, something went wrong.