* ```routes /last-origin/news.html ``` - [x] New Route / 新的路由 - [x] Follows [Script Standard](https://docs.rsshub.app/joinus/advanced/script-standard) / 跟随 [路由规范](https://docs.rsshub.app/zh/joinus/advanced/script-standard) - [ ] Documentation / 文档说明 - [x] Full text / 全文获取 - [x] Use cache / 使用缓存 - [ ] Anti-bot or rate limit / 反爬/频率限制 - [ ] If yes, do your code reflect this sign? / 如果有, 是否有对应的措施? - [x] [Date and time](https://docs.rsshub.app/joinus/advanced/pub-date) / [日期和时间](https://docs.rsshub.app/zh/joinus/advanced/pub-date) - [x] Parsed / 可以解析 - [x] Correct time zone / 时区正确 - [ ] New package added / 添加了新的包 - [ ] `Puppeteer` * Update lib/routes/last-origin/namespace.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/last-origin/news.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/last-origin/news.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/last-origin/news.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/last-origin/news.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/routes/last-origin/news.ts Co-authored-by: Tony <TonyRL@users.noreply.github.com> ---------
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { Route } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import ofetch from '@/utils/ofetch';
|
|
import { load } from 'cheerio';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
import timezone from '@/utils/timezone';
|
|
|
|
export const route: Route = {
|
|
path: '/news',
|
|
name: 'News',
|
|
url: 'www.last-origin.com',
|
|
maintainers: ['gudezhi'],
|
|
example: '/last-origin/news',
|
|
parameters: {},
|
|
categories: ['game'],
|
|
features: {
|
|
supportRadar: true,
|
|
},
|
|
radar: [
|
|
{
|
|
source: ['www.last-origin.com/news.html', 'www.last-origin.com'],
|
|
target: '/news',
|
|
},
|
|
],
|
|
handler,
|
|
description: '',
|
|
};
|
|
|
|
async function handler() {
|
|
const baseUrl = 'https://www.last-origin.com/news.html';
|
|
const response = await ofetch(baseUrl);
|
|
const $ = load(response);
|
|
|
|
const list = $('.contents .news_wrap')
|
|
.toArray()
|
|
.map((item) => {
|
|
const title = $(item).find('.news_title').text().trim();
|
|
const link = new URL($(item).find('a').attr('href')!, baseUrl).href;
|
|
const date = $(item).find('time').text().trim();
|
|
const pubDate = timezone(parseDate(date), +9);
|
|
return {
|
|
title,
|
|
link,
|
|
pubDate,
|
|
description: '',
|
|
};
|
|
});
|
|
|
|
const items = await Promise.all(
|
|
list.map((item) =>
|
|
cache.tryGet(item.link, async () => {
|
|
const response = await ofetch(item.link);
|
|
const $ = load(response);
|
|
item.description = $('.news_contents_editor').html() ?? '';
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
return {
|
|
title: 'LastOrigin官网公告',
|
|
link: baseUrl,
|
|
item: items,
|
|
};
|
|
}
|