Skip to content

Commit afacee1

Browse files
authored
Update posts.php
1 parent d844719 commit afacee1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

posts.php

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

66
try {
7-
// Load the RSS feed and convert it to an array
7+
// Load the Atom 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-
// Generate the list of all blog posts with full title and description
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 with full description
1521
$posts = '';
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
22+
foreach ($feed['entry'] as $post) {
23+
$date = date('d/m/Y', strtotime($post['updated'] ?? ''));
24+
$title = $post['title'] ?? 'No title';
25+
$link = $post['link']['@attributes']['href'] ?? '#';
26+
$description = isset($post['summary']) ? strip_tags($post['summary']) : ''; // Remove HTML tags for cleaner text
2127

2228
$posts .= sprintf(
2329
"\n* **[%s]** [%s](%s \"%s\")\n > %s",
@@ -49,4 +55,4 @@
4955
// Write the updated content to README.md
5056
file_put_contents($readmePath, $newContent);
5157

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

0 commit comments

Comments
 (0)