Browse Source

Magazine from RSS, continued

imwald
Nuša Pukšič 3 months ago
parent
commit
8e6dd8736e
  1. 8
      src/Command/RssFetchCommand.php
  2. 17
      src/Service/RssFeedService.php
  3. 20
      src/Service/RssToNostrConverter.php
  4. 2
      templates/layout.html.twig
  5. 4
      templates/pages/article.html.twig

8
src/Command/RssFetchCommand.php

@ -347,6 +347,14 @@ class RssFetchCommand extends Command @@ -347,6 +347,14 @@ class RssFetchCommand extends Command
$existing->setPublishedAt($item['pubDate']);
}
// Extract and set image from tags
foreach ($eventObject->tags as $tag) {
if ($tag[0] === 'image' && isset($tag[1])) {
$existing->setImage($tag[1]);
break;
}
}
// Extract and set summary from tags (now with HTML stripped)
foreach ($eventObject->tags as $tag) {
if ($tag[0] === 'summary' && isset($tag[1])) {

17
src/Service/RssFeedService.php

@ -121,6 +121,21 @@ class RssFeedService @@ -121,6 +121,21 @@ class RssFeedService
}
}
// Extract image from media:content
$imageUrl = null;
if (isset($namespaces['media'])) {
$mediaChildren = $item->children($namespaces['media']);
if (isset($mediaChildren->content)) {
foreach ($mediaChildren->content as $mediaContent) {
$medium = (string) $mediaContent['medium'];
if ($medium === 'image' || empty($medium)) {
$imageUrl = (string) $mediaContent['url'];
break;
}
}
}
}
// Parse publication date
$pubDate = null;
if (isset($item->pubDate)) {
@ -135,6 +150,7 @@ class RssFeedService @@ -135,6 +150,7 @@ class RssFeedService
'content' => $content,
'categories' => $categories,
'guid' => (string) ($item->guid ?? ''),
'image' => $imageUrl,
];
}
@ -186,4 +202,3 @@ class RssFeedService @@ -186,4 +202,3 @@ class RssFeedService
];
}
}

20
src/Service/RssToNostrConverter.php

@ -51,14 +51,8 @@ class RssToNostrConverter @@ -51,14 +51,8 @@ class RssToNostrConverter
$event = new Event();
$event->setKind(KindsEnum::LONGFORM->value);
// Set content
// Set content (without appending the link)
$content = $rssItem['content'] ?? $rssItem['description'] ?? '';
// If we have both content and link, append a reference
if (!empty($rssItem['link'])) {
$content .= "\n\n---\n\nOriginal article: " . $rssItem['link'];
}
$event->setContent($content);
// Generate unique slug from title and timestamp
@ -76,6 +70,11 @@ class RssToNostrConverter @@ -76,6 +70,11 @@ class RssToNostrConverter
$event->addTag(['summary', $summary]);
}
// Add image tag if available
if (!empty($rssItem['image'])) {
$event->addTag(['image', $rssItem['image']]);
}
// Add published_at tag
if ($rssItem['pubDate'] instanceof \DateTimeImmutable) {
$event->addTag(['published_at', (string) $rssItem['pubDate']->getTimestamp()]);
@ -86,7 +85,12 @@ class RssToNostrConverter @@ -86,7 +85,12 @@ class RssToNostrConverter
$event->addTag(['t', $matchedCategory['slug']]);
}
// Add reference to original URL
// Add source tag for original article URL
if (!empty($rssItem['link'])) {
$event->addTag(['source', $rssItem['link']]);
}
// Add reference to original URL (r tag for generic reference)
if (!empty($rssItem['link'])) {
$event->addTag(['r', $rssItem['link']]);
}

2
templates/layout.html.twig

@ -14,9 +14,11 @@ @@ -14,9 +14,11 @@
<li>
<a href="{{ path('reading_list_index') }}">Reading Lists</a>
</li>
{% if is_granted('ROLE_ADMIN') %}
<li>
<a href="{{ path('nzine_list') }}">My NZines</a>
</li>
{% endif %}
<li>
<a href="{{ path('app_search_index') }}">{{ 'heading.search'|trans }}</a>
</li>

4
templates/pages/article.html.twig

@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
{% endif %}
</div>
<div class="w-container">
<article class="w-container">
<div class="card">
<div class="card-header">
<h1 class="card-title">{{ article.title }}</h1>
@ -83,7 +83,7 @@ @@ -83,7 +83,7 @@
</div>
<twig:Organisms:Comments current="30023:{{ article.pubkey }}:{{ article.slug|e }}"></twig:Organisms:Comments>
</div>
</article>
{% endblock %}
{% block aside %}

Loading…
Cancel
Save