Files
RSSHub/lib/v2/onet/utils.js
T
Damian Kaczmarczyk 413c97a0cf feat(route): Add Onet (#14200)
* feat(route): Add Onet

* use arrow function in `router.js`

* Update lib/v2/onet/templates/article.art

* Update lib/v2/onet/templates/image.art

* Update lib/v2/onet/maintainer.js

* Update website/docs/routes/new-media.mdx

---------
2024-01-09 23:40:40 +08:00

52 lines
1.6 KiB
JavaScript

const { art } = require('@/utils/render');
const path = require('path');
const parseMainImage = ($) => {
const mainImage = $('figure.mainPhoto');
const img = mainImage.find('img');
const author = mainImage.find('span.copyright');
const caption = mainImage.find('span.imageDescription');
return art(path.join(__dirname, 'templates/image.art'), {
url: img.attr('src'),
alt: img.attr('alt')?.trim(),
author: author.text()?.trim(),
caption: caption.text()?.trim(),
});
};
const parseArticleContent = ($) => {
const content = $('[itemprop="articleBody"]');
$('*')
.contents()
.filter(function () {
return this.nodeType === 8;
})
.remove();
content.find('aside').remove();
content.find('.videoPlayerContainer').remove();
content.find('.pulsevideo').remove();
content.find('.adsContainer').remove();
content.find('.placeholder').remove();
content.find('.contentPremium').removeAttr('style');
content.find('div.image').each((i, el) => {
const img = $(el).find('img');
const author = $(el).find('span.author');
const caption = $(el).find('span.caption');
const html = art(path.join(__dirname, 'templates/image.art'), {
url: img.attr('src'),
alt: img.attr('alt')?.trim(),
caption: caption.text()?.trim(),
author: author.text()?.trim(),
});
$(el).replaceWith(html);
});
return content;
};
module.exports = {
parseArticleContent,
parseMainImage,
};