Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions lib/routes/chnmuseum/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { Router } from '@/types';

const router = (router: Router) => {
router.get('/zl', './zl');
};

export default router;
51 changes: 51 additions & 0 deletions lib/routes/chnmuseum/zl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 { Route } from '@/types';
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
import got from '@/utils/got';

export const route: Route = {
path: '/zl',
categories: ['travel'],
example: '/chnmuseum/zl',
name: '中国国家博物馆 - 展览',
maintainers: ['magazian'],
handler: async () => {
const baseUrl = 'https://www.chnmuseum.cn';
const url = `${baseUrl}/zl/`;

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

const list = $('ul#div li')
.toArray()
.map((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();
const duration = $item.find('div.cj_zxx2 p').text().trim();

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

return {
title: '中国国家博物馆 - 展览',
link: url,
item: list,
};
},
};
Loading