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.
feat(route/gis): Add route (DIYgod#16461)
* feat(route/gis): Add route * Update namespace.ts * Update lib/routes/gis/namespace.ts Co-authored-by: Tony <[email protected]> * Update index.ts * . ---------
- Loading branch information
Showing
2 changed files
with
66 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,60 @@ | ||
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: '/:path{.*}', | ||
categories: ['new-media'], | ||
example: '/gis/c/security-challenges/', | ||
parameters: { path: '包含"Reports"页面下的路径' }, | ||
name: '报告', | ||
maintainers: ['dzx-dzx'], | ||
radar: [ | ||
{ | ||
source: ['www.gisreportsonline.com'], | ||
}, | ||
], | ||
handler, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const rootUrl = 'https://www.gisreportsonline.com'; | ||
const currentUrl = `${rootUrl}/${ctx.req.param('path')}`; | ||
const response = await ofetch(currentUrl); | ||
|
||
const $ = load(response); | ||
|
||
const list = $('article h3 a') | ||
.toArray() | ||
.map((e) => ({ link: $(e).attr('href'), title: $(e).text() })); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const content = load(await ofetch(item.link)); | ||
const ldjson = JSON.parse(content('script.rank-math-schema-pro').text())['@graph'].find((e) => e['@type'] === 'NewsArticle'); | ||
|
||
item.pubDate = parseDate(ldjson.datePublished); | ||
item.updated = parseDate(ldjson.dateModified); | ||
item.author = [ldjson.author]; | ||
item.category = ldjson.keywords.split(','); | ||
item.language = ldjson.inLanguage; | ||
|
||
item.description = content('header.entry-header ~ :not(#pos-conclusion ~ *)') | ||
.toArray() | ||
.map((e) => content(e).html()) | ||
.join(''); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
return { | ||
title: $('title').text(), | ||
link: currentUrl, | ||
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: 'GIS Reports', | ||
url: 'www.gisreportsonline.com', | ||
}; |