-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(route/bjnews): Update to new standard (#16249)
* fix(route/bjnews): Update to new standard * . * . * Add column * Update lib/routes/bjnews/cat.ts Co-authored-by: Tony <[email protected]> * Update column.ts ---------
- Loading branch information
Showing
6 changed files
with
111 additions
and
47 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
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
import { Route } from '@/types'; | ||
import { load } from 'cheerio'; | ||
import ofetch from '@/utils/ofetch'; | ||
|
||
import { fetchArticle } from './utils'; | ||
|
||
export const route: Route = { | ||
path: '/cat/:cat', | ||
categories: ['traditional-media'], | ||
example: '/bjnews/cat/depth', | ||
parameters: { cat: '分类, 可从URL中找到' }, | ||
features: {}, | ||
radar: [ | ||
{ | ||
source: ['www.bjnews.com.cn/:cat'], | ||
}, | ||
], | ||
name: '分类', | ||
maintainers: ['dzx-dzx'], | ||
handler, | ||
url: 'www.bjnews.com.cn', | ||
}; | ||
|
||
async function handler(ctx) { | ||
const url = `https://www.bjnews.com.cn/${ctx.req.param('cat')}`; | ||
const res = await ofetch(url); | ||
const $ = load(res); | ||
const list = $('#waterfall-container .pin_demo > a') | ||
.toArray() | ||
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15) | ||
.map((a) => ({ | ||
title: $(a).text(), | ||
link: $(a).attr('href'), | ||
category: $(a).parent().find('.source').text().trim(), | ||
})); | ||
|
||
const out = await Promise.all(list.map((item) => fetchArticle(item))); | ||
return { | ||
title: $('title').text(), | ||
link: url, | ||
item: out, | ||
}; | ||
} |
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,43 @@ | ||
import { Route } from '@/types'; | ||
import ofetch from '@/utils/ofetch'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import timezone from '@/utils/timezone'; | ||
|
||
import { fetchArticle } from './utils'; | ||
|
||
export const route: Route = { | ||
path: '/column/:column', | ||
categories: ['traditional-media'], | ||
example: '/bjnews/column/204', | ||
parameters: { column: '栏目ID, 可从手机版网页URL中找到' }, | ||
features: {}, | ||
radar: [ | ||
{ | ||
source: ['m.bjnews.com.cn/column/:column.htm'], | ||
}, | ||
], | ||
name: '分类', | ||
maintainers: ['dzx-dzx'], | ||
handler, | ||
url: 'www.bjnews.com.cn', | ||
}; | ||
|
||
async function handler(ctx) { | ||
const columnID = ctx.req.param('column'); | ||
const url = `https://api.bjnews.com.cn/api/v101/news/column_news.php?column_id=${columnID}`; | ||
const res = await ofetch(url); | ||
const list = res.data.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15).map((e) => ({ | ||
title: e.row.title, | ||
guid: e.uuid, | ||
pubDate: timezone(parseDate(e.row.publish_time), +8), | ||
updated: timezone(parseDate(e.row.update_time), +8), | ||
link: `https://www.bjnews.com.cn/detail/${e.uuid}.html`, | ||
})); | ||
|
||
const out = await Promise.all(list.map((item) => fetchArticle(item))); | ||
return { | ||
title: `新京报 - 栏目 - ${res.data[0].row.column_info[0].column_name}`, | ||
link: `https://m.bjnews.com.cn/column/${columnID}.html`, | ||
item: out, | ||
}; | ||
} |
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.bjnews.com.cn', | ||
}; |
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,19 @@ | ||
import cache from '@/utils/cache'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import timezone from '@/utils/timezone'; | ||
import ofetch from '@/utils/ofetch'; | ||
import { load } from 'cheerio'; | ||
|
||
export function fetchArticle(item) { | ||
return cache.tryGet(item.link, async () => { | ||
const responses = await ofetch(item.link); | ||
const $d = load(responses); | ||
// $d('img').each((i, e) => $(e).attr('referrerpolicy', 'no-referrer')); | ||
|
||
item.pubDate = timezone(parseDate($d('.left-info .timer').text()), +8); | ||
item.author = $d('.left-info .reporter').text(); | ||
item.description = $d('#contentStr').html(); | ||
|
||
return item; | ||
}); | ||
} |