Skip to content

Commit

Permalink
Merge pull request #113 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Feb 1, 2024
2 parents ea7ccd0 + 670f6f3 commit aa037a9
Show file tree
Hide file tree
Showing 10 changed files with 2,887 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
REDIS_URL: redis://localhost:${{ job.services.redis.ports[6379] }}/
- name: Upload coverage to Codecov
if: ${{ matrix.node-version == '20' }}
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos as documented, but seems broken

Expand Down
1 change: 1 addition & 0 deletions lib/middleware/anti-hotlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const process = (html, image_hotlink_template, multimedia_hotlink_template, wrap
if (image_hotlink_template) {
replaceUrls($, 'img, picture > source', image_hotlink_template);
replaceUrls($, 'video[poster]', image_hotlink_template, 'poster');
replaceUrls($, '*[data-rsshub-image="href"]', image_hotlink_template, 'href');
}
if (multimedia_hotlink_template) {
replaceUrls($, 'video, video > source, audio, audio > source', multimedia_hotlink_template);
Expand Down
64 changes: 64 additions & 0 deletions lib/v2/caam/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const { category = '1' } = ctx.params;
const limit = ctx.query.limit ? Number.parseInt(ctx.query.limit, 10) : 30;

const rootUrl = 'http://www.caam.org.cn';
const currentUrl = new URL(`chn/1/cate_${category}/list_1.html`, rootUrl).href;

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

const $ = cheerio.load(response);

let items = $('span.cont')
.slice(0, limit)
.toArray()
.map((item) => {
item = $(item);

const a = item.parent();

return {
title: item.text(),
link: new URL(a.prop('href'), currentUrl).href,
pubDate: parseDate(a.find('span.time').text(), '[YYYY.MM.DD]'),
};
});

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

const content = cheerio.load(detailResponse);

const infoEls = content('div.fourTop em');

item.title = content('div.fourTop h2').text();
item.description = content('div.fourBox').html();
item.author = infoEls.length <= 1 ? undefined : content('div.fourTop em').last().text();
item.pubDate = parseDate(infoEls.first().text());

return item;
})
)
);

const author = $('div.footer a').first().text();
const subtitle = $('div.topMeuns ul li a').last().text();
const image = new URL('images/header-back-7.png', rootUrl).href;

ctx.state.data = {
item: items,
title: `${author} - ${subtitle}`,
link: currentUrl,
description: $('meta[property="og:description"]').prop('content'),
language: $('html').prop('lang'),
image,
subtitle,
author,
};
};
3 changes: 3 additions & 0 deletions lib/v2/caam/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:category?': ['nczitzk'],
};
Loading

0 comments on commit aa037a9

Please sign in to comment.