1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-01-16 13:50:01 +01:00

[CssSelectorBridge] Time/Thumbnail improvements (#3879) (#3901)

* Implement <time> metadata tag as timestamp source
* Add setting to include thumbnail as article header
This commit is contained in:
ORelio 2024-01-19 21:30:53 +01:00 committed by GitHub
parent 12a90e2074
commit bb36eb9eb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 5 deletions

View File

@ -56,6 +56,11 @@ class CssSelectorBridge extends BridgeAbstract
'title' => 'Some sites set their logo as thumbnail for every article. Use this option to discard it.',
'type' => 'checkbox',
],
'thumbnail_as_header' => [
'name' => '[Optional] Insert thumbnail as article header',
'title' => 'Insert article main image on top of article contents.',
'type' => 'checkbox',
],
'limit' => self::LIMIT
]
];
@ -89,6 +94,7 @@ class CssSelectorBridge extends BridgeAbstract
$content_cleanup = $this->getInput('content_cleanup');
$title_cleanup = $this->getInput('title_cleanup');
$discard_thumbnail = $this->getInput('discard_thumbnail');
$thumbnail_as_header = $this->getInput('thumbnail_as_header');
$limit = $this->getInput('limit') ?? 10;
$html = defaultLinkTo(getSimpleHTMLDOM($this->homepageUrl), $this->homepageUrl);
@ -109,6 +115,9 @@ class CssSelectorBridge extends BridgeAbstract
if ($discard_thumbnail && isset($item['enclosures'])) {
unset($item['enclosures']);
}
if ($thumbnail_as_header && isset($item['enclosures'][0])) {
$item['content'] = '<p><img src="' . $item['enclosures'][0] . '" /></p>' . $item['content'];
}
$this->items[] = $item;
}
}
@ -311,6 +320,7 @@ class CssSelectorBridge extends BridgeAbstract
// Facebook Open Graph (og:KEY) - https://developers.facebook.com/docs/sharing/webmasters
// Twitter (twitter:KEY) - https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started
// Standard meta tags - https://www.w3schools.com/tags/tag_meta.asp
// Standard time tag - https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time
// Each Entry field mapping defines a list of possible <meta> tags names that contains the expected value
static $meta_mappings = [
@ -323,16 +333,16 @@ class CssSelectorBridge extends BridgeAbstract
'uri' => [
'og:url',
'twitter:url',
'canonical'
'canonical',
],
'title' => [
'og:title',
'twitter:title'
'twitter:title',
],
'content' => [
'og:description',
'twitter:description',
'description'
'description',
],
'timestamp' => [
'article:published_time',
@ -342,7 +352,8 @@ class CssSelectorBridge extends BridgeAbstract
'article:modified_time',
'og:article:modified_time',
'lastModified',
'lastmodified'
'lastmodified',
'time',
],
'enclosures' => [
'og:image:secure_url',
@ -350,7 +361,7 @@ class CssSelectorBridge extends BridgeAbstract
'og:image',
'twitter:image',
'thumbnailImg',
'thumbnailimg'
'thumbnailimg',
],
'author' => [
'article:author',
@ -375,6 +386,8 @@ class CssSelectorBridge extends BridgeAbstract
$element = null;
if ($field === 'canonical') {
$element = $entry_html->find('link[rel=canonical]');
} else if ($field === 'time') {
$element = $entry_html->find('time[datetime]');
} else {
$element = $entry_html->find("meta[property=$field], meta[name=$field]");
}
@ -384,6 +397,8 @@ class CssSelectorBridge extends BridgeAbstract
$field_value = '';
if ($field === 'canonical') {
$field_value = $element->href;
} else if ($field === 'time') {
$field_value = $element->datetime;
} else {
$field_value = $element->content;
}

View File

@ -37,6 +37,11 @@ class CssSelectorFeedExpanderBridge extends CssSelectorBridge
'title' => 'Some sites set their logo as thumbnail for every article. Use this option to discard it.',
'type' => 'checkbox',
],
'thumbnail_as_header' => [
'name' => '[Optional] Insert thumbnail as article header',
'title' => 'Insert article main image on top of article contents.',
'type' => 'checkbox',
],
'limit' => self::LIMIT
]
];
@ -48,6 +53,7 @@ class CssSelectorFeedExpanderBridge extends CssSelectorBridge
$content_cleanup = $this->getInput('content_cleanup');
$dont_expand_metadata = $this->getInput('dont_expand_metadata');
$discard_thumbnail = $this->getInput('discard_thumbnail');
$thumbnail_as_header = $this->getInput('thumbnail_as_header');
$limit = $this->getInput('limit');
$feedParser = new FeedParser();
@ -100,6 +106,13 @@ class CssSelectorFeedExpanderBridge extends CssSelectorBridge
unset($item_expanded['enclosures']);
}
if ($thumbnail_as_header && isset($item_expanded['enclosures'][0])) {
$item_expanded['content'] = '<p><img src="'
. $item_expanded['enclosures'][0]
. '" /></p>'
. $item_expanded['content'];
}
$this->items[] = $item_expanded;
}
}

View File

@ -58,6 +58,11 @@ class SitemapBridge extends CssSelectorBridge
'title' => 'Some sites set their logo as thumbnail for every article. Use this option to discard it.',
'type' => 'checkbox',
],
'thumbnail_as_header' => [
'name' => '[Optional] Insert thumbnail as article header',
'title' => 'Insert article main image on top of article contents.',
'type' => 'checkbox',
],
'limit' => self::LIMIT
]
];
@ -71,6 +76,7 @@ class SitemapBridge extends CssSelectorBridge
$title_cleanup = $this->getInput('title_cleanup');
$site_map = $this->getInput('site_map');
$discard_thumbnail = $this->getInput('discard_thumbnail');
$thumbnail_as_header = $this->getInput('thumbnail_as_header');
$limit = $this->getInput('limit');
$this->feedName = $this->titleCleanup($this->getPageTitle($this->homepageUrl), $title_cleanup);
@ -87,6 +93,9 @@ class SitemapBridge extends CssSelectorBridge
if ($discard_thumbnail && isset($item['enclosures'])) {
unset($item['enclosures']);
}
if ($thumbnail_as_header && isset($item['enclosures'])) {
$item['content'] = '<p><img src="' . $item['enclosures'][0] . '" /></p>' . $item['content'];
}
$this->items[] = $item;
}
}