feat: better compatibility fo AEON & NYTimes (#6054)

This commit is contained in:
Enoch Ma 2020-10-30 17:44:38 +08:00 committed by GitHub
parent aed981c4ff
commit 4e31222c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 12 deletions

View File

@ -33,7 +33,7 @@ module.exports = async (ctx) => {
let bio;
const authorInfo = '.article__body__author-details > p:nth-child(2)';
if (capture(authorInfo).html() !== null) {
bio = `<br><br><br><br><hr><br><b>` + author.trim() + '</b> ' + capture(authorInfo).html().trim() + `<p><hr>`;
bio = `<br><br><hr><br><b>` + author.trim() + '</b> ' + capture(authorInfo).html().trim() + `<p></p><hr>`;
capture('.article__inline-sidebar').remove();
} else {
bio = '';

View File

@ -86,7 +86,7 @@ module.exports = async (ctx) => {
const ending = /&#x611F;(&#x8C22|&#x8B1D);.*?cn\.letters@nytimes\.com&#x3002;/g;
const matching = '<div class="article-paragraph">';
const formatted = '<p></p>' + matching;
const formatted = '<br>' + matching;
single.description = result.description.replace(ending, '').split(matching).join(formatted);

View File

@ -37,7 +37,7 @@ module.exports = async (ctx) => {
const ending = /&#x611F;(&#x8C22|&#x8B1D);.*?cn\.letters@nytimes\.com&#x3002;/g;
const matching = '<div class="article-paragraph">';
const formatted = '<p></p>' + matching;
const formatted = '<br>' + matching;
item.description = result.description.replace(ending, '').split(matching).join(formatted);

View File

@ -27,19 +27,28 @@ module.exports = async function get_article(url) {
let date = new Date(date_str);
date.setHours(date.getHours() - 8);
date = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
const title = $('div.block_m > div.ct_tittle > div.bg_htit > h2').text();
const category = $('div.icon_float > a').attr('title');
const author = $('div.talk_time > b')
.text()
.replace(/^来自(.*)部门$/g, '$1');
$('div.ct_tittle').remove();
$('div.talk_time').remove();
const description = $('div.block_m')
.html()
.replace(/(href.*?)<u>(.*?)<\/u>/g, `$1$2`)
.replace(/href="\//g, 'href="' + domain + '/')
// Preserve the not extremely disturbing donation ad
// to support the site.
.replace(/(<img.*liiLIZF8Uh6yM.*?>)/g, `<br><br>$1`);
const item = {
title: $('div.block_m > div.ct_tittle > div.bg_htit > h2').text(),
title: title,
pubDate: date.toUTCString(),
author: $('div.talk_time > b')
.text()
.replace(/^来自(.*)部门$/g, '$1'),
author: author,
link: url,
description: $('div.p_mainnew')
.html()
.replace(/(href.*?)<u>(.*?)<\/u>/g, `$1$2`)
.replace(/href="\//g, 'href="' + domain + '/'),
category: $('div.icon_float > a').attr('title'),
description: description,
category: category,
};
return item;
};