|
4 | 4 | require_once __DIR__ . '/vendor/autoload.php';
|
5 | 5 |
|
6 | 6 | try {
|
7 |
| - // Load the RSS feed and convert to an array |
| 7 | + // Load the RSS feed and convert it to an array |
8 | 8 | $feed = Feed::loadAtom('https://sharpapi.com/feed')->toArray();
|
9 | 9 | } catch (Exception $e) {
|
10 | 10 | echo "Failed to load feed: ", $e->getMessage();
|
11 | 11 | exit(1);
|
12 | 12 | }
|
13 | 13 |
|
14 |
| -// Generate the list of blog posts |
| 14 | +// Initialize an empty string to store the formatted posts |
15 | 15 | $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 | + ); |
51 | 32 | }
|
52 | 33 |
|
53 | 34 | // Load README.md content
|
|
0 commit comments