feat(route): add back lianxh (#15365)

* feat(route): add back lianxh

* fix: feed title
This commit is contained in:
Tony 2024-04-25 05:53:46 +08:00 committed by GitHub
parent 8a11f0e756
commit 9550a9f426
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 123 additions and 0 deletions

116
lib/routes/lianxh/index.ts Normal file
View File

@ -0,0 +1,116 @@
import { DataItem, Route } from '@/types';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
import * as cheerio from 'cheerio';
import type { Context } from 'hono';
import markdownit from 'markdown-it';
const md = markdownit({
html: true,
breaks: true,
});
export const route: Route = {
path: '/:category?',
example: '/lianxh',
parameters: { category: '分类 id可在对应分类页 URL 中找到,默认为 `all`,即全部' },
radar: [
{
source: ['www.lianxh.cn/blogs/all.html', 'www.lianxh.cn/'],
},
],
name: '精彩资讯',
maintainers: ['nczitzk'],
handler,
url: 'www.lianxh.cn/',
description: `| 分类 | id |
-------------------- | --- |
| all |
Stata | 16 |
Stata | 17 |
| 18 |
- | 19 |
| 20 |
- - | 21 |
| 22 |
| 23 |
Stata | 24 |
| 25 |
Stata | 26 |
Probit-Logit | 27 |
| 28 |
- | 29 |
Markdown-LaTeX | 30 |
| 31 |
| 32 |
| 33 |
| 34 |
Stata | 35 |
- | 36 |
Python-R-Matlab | 37 |
IV-GMM | 38 |
DID | 39 |
RDD | 40 |
PSM-Matching | 41 |
| 42 |
Stata | 43 |
| 44 |
| 45 |
| 46 |
| 47 |
| 48 |
SFA-DEA - | 49 |
- | 50 |
| 51 |
| 52 |
| 53 |`,
};
async function handler(ctx: Context) {
const { category = 'all' } = ctx.req.param();
const rootUrl = 'https://www.lianxh.cn';
const currentUrl = `${rootUrl}/blogs/${category}.html`;
const response = await ofetch(currentUrl);
const $ = cheerio.load(response);
const list = $('.card-body > a')
.slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')!, 10) : 30)
.toArray()
.map((item) => {
const $item = $(item);
const href = $item.attr('href');
return {
title: $item.find('h5').text().trim(),
link: rootUrl + href,
id: href?.split('/').pop()?.split('.')[0],
};
}) as DataItem[];
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link!, async () => {
const { data: response } = await ofetch(`${rootUrl}/web-api/article`, {
query: {
id: item.id,
},
});
item.description = md.render(response.details);
item.pubDate = parseDate(response.release_time, 'YYYY-MM-DD');
item.author = response.author;
return item;
})
)
);
return {
title: `连享会 - ${$('.card-title').text()}`,
link: currentUrl,
item: items as DataItem[],
};
}

View File

@ -0,0 +1,7 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '连享会',
url: 'www.lianxh.cn',
categories: ['programming'],
};