Skip to content

Commit c3848b3

Browse files
authored
Update posts.php
1 parent 31de4db commit c3848b3

File tree

1 file changed

+18
-37
lines changed

1 file changed

+18
-37
lines changed

posts.php

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

66
try {
7-
// Load the RSS feed and convert 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-
// Generate the list of blog posts
14+
// Initialize an empty string to store the formatted posts
1515
$posts = '';
16-
if (isset($feed['entry']) && is_array($feed['entry'])) {
17-
foreach ($feed['entry'] as $post) {
18-
// Format the date
19-
$date = isset($post['updated']) ? date('d/m/Y', strtotime($post['updated'])) : 'Unknown Date';
20-
21-
// Ensure title is available
22-
$title = $post['title'] ?? 'Untitled';
23-
24-
// Extract the link URL
25-
if (isset($post['link'])) {
26-
if (is_array($post['link'])) {
27-
$link = $post['link']['@attributes']['href'] ?? '#';
28-
} else {
29-
$link = $post['link'];
30-
}
31-
} else {
32-
$link = '#';
33-
}
34-
35-
// Extract the description or summary
36-
$description = '';
37-
if (isset($post['summary'])) {
38-
$description = is_string($post['summary']) ? strip_tags($post['summary']) : (isset($post['summary'][0]) ? strip_tags($post['summary'][0]) : '');
39-
}
40-
41-
// Format each post entry
42-
$posts .= sprintf(
43-
"\n* **[%s]** [%s](%s \"%s\")\n > %s",
44-
$date,
45-
$title,
46-
$link,
47-
$title,
48-
$description
49-
);
50-
}
16+
foreach ($feed['entry'] as $post) {
17+
// Extract title, link, and summary
18+
$title = $post['title'] ?? 'No title';
19+
$link = $post['link'][0]['@attributes']['href'] ?? '#';
20+
$description = $post['summary'] ?? '';
21+
$date = date('d/m/Y', strtotime($post['updated']));
22+
23+
// Append each post's details in the required format
24+
$posts .= sprintf(
25+
"\n* **[%s]** [%s](%s \"%s\")\n > %s\n",
26+
$date,
27+
strip_tags($title),
28+
$link,
29+
strip_tags($title),
30+
strip_tags($description)
31+
);
5132
}
5233

5334
// Load README.md content

0 commit comments

Comments
 (0)