Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions lib/routes/chnmuseum/zl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { load } from 'cheerio';

Check failure

Code scanning / oxlint

simple-import-sort(imports) Error

Run autofix to sort these imports!
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
import type { Context } from 'hono';

import cache from '@/utils/cache';
import got from '@/utils/got';

import type { Data, DataItem, Route } from '@/types';

export const route: Route = {
path: '/zl',
categories: ['travel'],
example: '/chnmuseum/zl',
name: 'Current Exhibitions',
maintainers: ['magazian'],
radar: [
{
source: ['https://www.chnmuseum.cn/zl/'],
target: '/zl',
},
],
handler: async (ctx: Context): Promise<Data> => {

Check failure

Code scanning / oxlint

eslint(no-unused-vars) Error

Parameter 'ctx' is declared but never used. Unused parameters should start with a '_'.
Consider removing this parameter.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
const baseUrl = 'https://www.chnmuseum.cn';
const url = `${baseUrl}/zl/`;

const response = await got(url);
const $ = load(response.data);

const list: DataItem[] = await Promise.all(
$('ul#div li')
.toArray()
.map(async (item) => {
const $item = $(item);
const $link = $item.find('a.recurl');

const relativeLink = $link.attr('href') || '';
const itemLink = relativeLink.startsWith('.')
? new URL(relativeLink, url).href
: `${baseUrl}${relativeLink}`;

const title = $item.find('div.cj_zxx3 p').text().trim();
const imgUrl = new URL($item.find('img').first().attr('src') || '', url).href;
const location = $item.find('div.cj_zxx1').text().trim();
let duration = $item.find('div.cj_zxx2 p').text().trim();

if (duration.endsWith('...') || duration.endsWith('……')) {
duration = (await cache.tryGet(itemLink, async () => {
const detailResponse = await got(itemLink);
const html = detailResponse.data;
const dateRegex = /var\s+qtxszq\s*=\s*"(.*?)";/;
const match = html.match(dateRegex);
return match && match[1] ? match[1] : duration;
})) as string;
}

return {
title,
link: itemLink,
description: `<div><img src="${imgUrl}" /><br /><p><b>地点:</b>${location}</p><p><b>展期:</b>${duration}</p></div>`,
};
})
);

return {
title: '中国国家博物馆 - 正在展出',
link: url,
language: 'zh-CN',
item: list,
};
},
};
Loading