Skip to content

Commit f02b1cc

Browse files
authored
Update posts.php
1 parent 214fae4 commit f02b1cc

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

posts.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@
44
require_once __DIR__ . '/vendor/autoload.php';
55

66
try {
7-
// Load the RSS feed and convert 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+
// 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+
1420
// Limit to the latest 5 posts (adjust if needed)
1521
$posts = '';
16-
foreach (array_slice($feed['item'], 0, 5) as $post) {
17-
$date = date('d/m/Y', strtotime($post['pubDate']));
18-
$posts .= sprintf("\n* **[%s]** [%s](%s \"%s\")", $date, $post['title'], $post['link'], $post['title']);
22+
foreach (array_slice($feed['entry'], 0, 5) as $post) {
23+
$date = date('d/m/Y', strtotime($post['updated'] ?? ''));
24+
$posts .= sprintf(
25+
"\n* **[%s]** [%s](%s \"%s\")",
26+
$date,
27+
$post['title'] ?? 'No title',
28+
$post['link']['@attributes']['href'] ?? '#',
29+
$post['title'] ?? 'No title'
30+
);
1931
}
2032

2133
// Load README.md content

0 commit comments

Comments
 (0)