Skip to content

Commit 4981ab8

Browse files
authored
Create posts.php
1 parent 8c433c0 commit 4981ab8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

posts.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
// Load Composer's autoload
4+
require_once __DIR__ . '/vendor/autoload.php';
5+
6+
// Load the RSS feed
7+
$feed = Feed::loadRss('https://sharpapi.com/feed')->toArray();
8+
9+
// Generate the list of blog posts
10+
$posts = '';
11+
foreach (array_slice($feed['item'], 0, 555) as $post) {
12+
$date = date('d/m/Y', strtotime($post['pubDate']));
13+
$posts .= sprintf("\n* **[%s]** [%s](%s \"%s\")", $date, $post['title'], $post['link'], $post['title']);
14+
}
15+
16+
// Generate the new content
17+
$content = preg_replace(
18+
'#<!-- posts -->.*<!-- /posts -->#s',
19+
sprintf('<!-- posts -->%s<!-- /posts -->', $posts),
20+
file_get_contents('README.md')
21+
);
22+
23+
// Overwrite the file
24+
file_put_contents('README.md', $content);

0 commit comments

Comments
 (0)