Skip to content

Commit 031e857

Browse files
authored
Update posts.php
1 parent a813855 commit 031e857

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

posts.php

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,31 @@
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 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 with full description
14+
// Generate the list of blog posts
2115
$posts = '';
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
27-
28-
$posts .= sprintf(
29-
"\n* **[%s]** [%s](%s \"%s\")\n > %s",
30-
$date,
31-
$title,
32-
$link,
33-
$title,
34-
$description
35-
);
16+
if (isset($feed['entry']) && is_array($feed['entry'])) {
17+
foreach ($feed['entry'] as $post) {
18+
$date = date('d/m/Y', strtotime($post['updated'] ?? ''));
19+
$title = $post['title'] ?? 'Untitled';
20+
$link = $post['link']['@attributes']['href'] ?? '#';
21+
$description = strip_tags($post['summary'] ?? ''); // Strip HTML tags for cleaner README
22+
23+
$posts .= sprintf(
24+
"\n* **[%s]** [%s](%s \"%s\")\n > %s",
25+
$date,
26+
$title,
27+
$link,
28+
$title,
29+
$description
30+
);
31+
}
3632
}
3733

3834
// Load README.md content

0 commit comments

Comments
 (0)