aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2022-09-21 22:20:51 +0200
committerGravatar GitHub <noreply@github.com> 2022-09-21 22:20:51 +0200
commitaabbeef743b1d9c15d151d485e14d0e6137d824f (patch)
treefac6c5005421733a655cc894b897e96fb3fbf3a3 /README.md
parent8d8fe66aab916a63cd04eb129a91122c14e8c623 (diff)
downloadrss-bridge-aabbeef743b1d9c15d151d485e14d0e6137d824f.tar.gz
rss-bridge-aabbeef743b1d9c15d151d485e14d0e6137d824f.tar.zst
rss-bridge-aabbeef743b1d9c15d151d485e14d0e6137d824f.zip
docs: add a better bridge example in readme (#3057)
Diffstat (limited to 'README.md')
-rw-r--r--README.md49
1 files changed, 37 insertions, 12 deletions
diff --git a/README.md b/README.md
index 7b592483..d53bff36 100644
--- a/README.md
+++ b/README.md
@@ -101,28 +101,53 @@ modify the `repository` in `scalingo.json`. See https://github.com/RSS-Bridge/rs
Learn more in
[Installation](https://rss-bridge.github.io/rss-bridge/For_Hosts/Installation.html).
-### Create a bridge
+### Create a new bridge from scratch
-Create the new bridge in e.g. `bridges/ExecuteBridge.php`:
+Create the new bridge in e.g. `bridges/BearBlogBridge.php`:
```php
<?php
-class ExecuteBridge extends BridgeAbstract
+class BearBlogBridge extends BridgeAbstract
{
- const NAME = 'Execute Program Blog';
+ const NAME = 'BearBlog (bearblog.dev)';
public function collectData()
{
- $url = 'https://www.executeprogram.com/api/pages/blog';
- $data = json_decode(getContents($url));
-
- foreach ($data->posts as $post) {
- $this->items[] = [
- 'uri' => sprintf('https://www.executeprogram.com/blog/%s', $post->slug),
- 'title' => $post->title,
- 'content' => $post->body,
+ // We can perform css selectors on $dom
+ $dom = getSimpleHTMLDOM('https://herman.bearblog.dev/blog/');
+
+ // An array of dom nodes
+ $blogPosts = $dom->find('.blog-posts li');
+
+ foreach ($blogPosts as $blogPost) {
+ // Select the anchor at index 0 (the first anchor found)
+ $a = $blogPost->find('a', 0);
+
+ // Select the inner text of the anchor
+ $title = $a->innertext;
+
+ // Select the href attribute of the anchor
+ $url = $a->href;
+
+ // Select the <time> tag
+ $time = $blogPost->find('time', 0);
+ // Create a \DateTime object from the datetime attribute
+ $createdAt = date_create_from_format('Y-m-d', $time->datetime);
+
+ $item = [
+ 'title' => $title,
+ 'author' => 'Herman',
+
+ // Prepend the url because $url is a relative path
+ 'uri' => 'https://herman.bearblog.dev' . $url,
+
+ // Grab the unix timestamp
+ 'timestamp' => $createdAt->getTimestamp(),
];
+
+ // Add the item to the list of items
+ $this->items[] = $item;
}
}
}