Skip to content

Commit 1fcc4a5

Browse files
authored
Update posts.php
1 parent 4fc41d1 commit 1fcc4a5

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

posts.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,28 @@
44
require_once __DIR__ . '/vendor/autoload.php';
55

66
try {
7-
// Load the Atom feed and convert it to an array
7+
// Load the RSS feed and convert it to an array
88
$feed = Feed::loadAtom('https://sharpapi.com/feed')->toArray();
99
} catch (Exception $e) {
1010
echo "Failed to load feed: ", $e->getMessage();
1111
exit(1);
1212
}
1313

14-
// Check if 'entry' key exists and contains data
15-
if (!isset($feed['entry']) || !is_array($feed['entry']) || empty($feed['entry'])) {
16-
echo "Feed data is missing or 'entry' key is not available.\n";
17-
exit(1);
18-
}
19-
20-
// Generate the list of all blog posts
14+
// Generate the list of all blog posts with full title and description
2115
$posts = '';
22-
foreach ($feed['entry'] as $post) {
23-
$date = date('d/m/Y', strtotime($post['updated'] ?? ''));
16+
foreach ($feed['item'] as $post) {
17+
$date = date('d/m/Y', strtotime($post['pubDate']));
18+
$title = $post['title'];
19+
$link = $post['link'];
20+
$description = strip_tags($post['description']); // Remove any HTML tags from description
21+
2422
$posts .= sprintf(
25-
"\n* **[%s]** [%s](%s \"%s\")",
23+
"\n* **[%s]** [%s](%s \"%s\")\n > %s",
2624
$date,
27-
$post['title'] ?? 'No title',
28-
$post['link']['@attributes']['href'] ?? '#',
29-
$post['title'] ?? 'No title'
25+
$title,
26+
$link,
27+
$title,
28+
$description
3029
);
3130
}
3231

@@ -50,4 +49,4 @@
5049
// Write the updated content to README.md
5150
file_put_contents($readmePath, $newContent);
5251

53-
echo "README.md updated successfully with all blog posts.\n";
52+
echo "README.md updated successfully with the latest blog posts.\n";

0 commit comments

Comments
 (0)