Skip to content

Commit

Permalink
feat(route): add 国门传媒在线中国海关 (#17093)
Browse files Browse the repository at this point in the history
* feat(route): add 国门传媒在线中国海关

* fix: categories

---------
  • Loading branch information
nczitzk authored Oct 13, 2024
1 parent 5360e26 commit bb74dad
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
130 changes: 130 additions & 0 deletions lib/routes/gmcmonline/chinacustoms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { Route } from '@/types';

import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';

export const handler = async (ctx) => {
const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10;

const rootUrl = 'http://chinacustoms.gmcmonline.com';
const magRootUrl = 'http://manager.gmcmonline.com';

const { data: response } = await got(rootUrl);

const $ = load(response);

const author = $('p.copyright a').text();
const language = $('html').prop('lang');

let items = $('ul.booklist li a')
.toArray()
.slice(0, limit)
.map((item) => {
item = $(item);

const title = item.find('p.txt').text();
const image = new URL(item.find('img').prop('src'), rootUrl).href;

return {
title,
link: new URL(item.prop('href'), rootUrl).href,
pubDate: parseDate(title, 'YYYY年MM期'),
author,
image,
banner: image,
language,
};
});

items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);

const $$ = load(detailResponse);

$$('ol.breadcrumb li a').first().remove();

const current = $$('ol.breadcrumb li a').first().text();
const pubDate = parseDate($$('div.title').text(), 'YYYY年MM月DD日');
const image = new URL($$('div.coverline img').prop('src'), rootUrl).href;

return $$('a.txt')
.toArray()
.map((i) => {
i = $(i);

const id = i.prop('href').match(/c\/(\d+)\.shtml/)?.[1] ?? undefined;

if (!id) {
return;
}

const title = i.prop('title') || i.text();
const guid = `gmcmonline-chinacustoms-${id}`;

return {
title,
pubDate,
link: new URL(i.prop('href'), item.link).href,
category: [current, i.closest('div.class-box').find('div.title-box span').text().replaceAll(/【|】/g, '') || undefined].filter(Boolean),
author,
guid,
id: guid,
image,
banner: image,
language,
enclosure_url: new URL(`front/article/${id}/pdf?magazineID=2`, magRootUrl).href,
enclosure_type: 'application/pdf',
enclosure_title: title,
};
})
.filter(Boolean);
})
)
);

const title = $('title').text();
const image = new URL($('div.img-box img').prop('src'), rootUrl).href;

return {
title,
description: title,
link: rootUrl,
item: items.flat(),
allowEmpty: true,
image,
author: title,
language,
};
};

export const route: Route = {
path: '/chinacustoms',
name: '中国海关',
url: 'chinacustoms.gmcmonline.com',
maintainers: ['nczitzk'],
handler,
example: '/gmcmonline/chinacustoms',
parameters: undefined,
description: undefined,
categories: ['reading'],

features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportRadar: true,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['chinacustoms.gmcmonline.com'],
target: '/chinacustoms',
},
],
};
8 changes: 8 additions & 0 deletions lib/routes/gmcmonline/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { Namespace } from '@/types';

export const namespace: Namespace = {
name: '国门传媒在线',
url: 'gmcmonline.com',
categories: ['journal'],
description: '',
};

0 comments on commit bb74dad

Please sign in to comment.