|
4 | 4 | require_once __DIR__ . '/vendor/autoload.php'; |
5 | 5 |
|
6 | 6 | try { |
7 | | - // Load the Atom feed and convert it 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 | | -// 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 |
| 14 | +// Generate the list of all blog posts with full title and description |
21 | 15 | $posts = ''; |
22 | | -foreach ($feed['entry'] as $post) { |
23 | | - $date = date('d/m/Y', strtotime($post['updated'] ?? '')); |
| 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 |
| 21 | + |
24 | 22 | $posts .= sprintf( |
25 | | - "\n* **[%s]** [%s](%s \"%s\")", |
| 23 | + "\n* **[%s]** [%s](%s \"%s\")\n > %s", |
26 | 24 | $date, |
27 | | - $post['title'] ?? 'No title', |
28 | | - $post['link']['@attributes']['href'] ?? '#', |
29 | | - $post['title'] ?? 'No title' |
| 25 | + $title, |
| 26 | + $link, |
| 27 | + $title, |
| 28 | + $description |
30 | 29 | ); |
31 | 30 | } |
32 | 31 |
|
|
50 | 49 | // Write the updated content to README.md |
51 | 50 | file_put_contents($readmePath, $newContent); |
52 | 51 |
|
53 | | -echo "README.md updated successfully with all blog posts.\n"; |
| 52 | +echo "README.md updated successfully with the latest blog posts.\n"; |
0 commit comments