Skip to content

Commit

Permalink
feat(route): add route of qiche365 (DIYgod#16834)
Browse files Browse the repository at this point in the history
* feat(route): add feed for qiche365

* feat: add timezone

* feat: format url

* feat: image maybe undefined

* fix: solve review
  • Loading branch information
huanfe1 committed Sep 20, 2024
1 parent 7678f8c commit f10693f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/routes/qiche365/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: 'ζ±½θ½¦ε¬ε›žη½‘',
url: 'qiche365.org.cn',
};
53 changes: 53 additions & 0 deletions lib/routes/qiche365/recall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Route, Data, DataItem } from '@/types';
import ofetch from '@/utils/ofetch';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';

const baseUrl = 'https://www.qiche365.org.cn';

export const route: Route = {
path: '/recall/:channel',
name: 'ζ±½θ½¦ε¬ε›ž',
example: '/qiche365/recall/1',
parameters: { channel: 'ι’‘ι“οΌŒθ§δΈ‹θ‘¨' },
description: `| ε›½ε†…ε¬ε›žζ–°ι—» | ε›½ε†…ε¬ε›žε…¬ε‘Š | ε›½ε€–ε¬ε›žζ–°ι—» | ε›½ε€–ε¬ε›žε…¬ε‘Š |
| ------------ | ------------ | ------------ | ------------ |
| 1 | 2 | 3 | 4 |`,
categories: ['government'],
maintainers: ['huanfe1'],
handler,
url: 'qiche365.org.cn/index/recall/index.html',
};

async function handler(ctx): Promise<Data> {
const { channel } = ctx.req.param();

const { html } = await ofetch(`${baseUrl}/index/recall/index/item/${channel}.html?loadmore=1`, {
method: 'get',
headers: {
'Accept-Language': 'zh-CN,zh;q=0.9',
},
});

const $ = load(<string>html);
const items: DataItem[] = $('li')
.toArray()
.map((item) => {
const cheerioItem = $(item);
return {
title: cheerioItem.find('h1').text(),
link: `${baseUrl}${cheerioItem.find('a').attr('href')}`,
pubDate: timezone(parseDate(cheerioItem.find('h2').html()!.match('</i>(.*?)<b>')![1]), +8),
description: cheerioItem.find('p').text().trim(),
author: cheerioItem.find('h3 span').text(),
image: cheerioItem.find('img').attr('src') && `${baseUrl}${cheerioItem.find('img').attr('src')}`,
};
});
return {
title: ['ε›½ε†…ε¬ε›žε…¬ε‘Š', 'ε›½ε†…ε¬ε›žζ–°ι—»', 'ε›½ε€–ε¬ε›žε…¬ε‘Š', 'ε›½ε€–ε¬ε›žζ–°ι—»'][channel - 1],
link: `${baseUrl}/index/recall/index.html`,
item: items,
language: 'zh-CN',
};
}

0 comments on commit f10693f

Please sign in to comment.