|
| 1 | +<?php |
| 2 | + |
| 3 | +use Aschmelyun\BasicFeeds\Feed; |
| 4 | +use Michelf\MarkdownExtra; |
| 5 | +require_once "remote/atom.gen.php"; # https://starbeamrainbowlabs.com/code/phpatomgenerator/ |
| 6 | +global $posts, $posts_updated; |
| 7 | +$host = "https://j0.lol"; |
| 8 | + |
| 9 | +/// Thx php docs |
| 10 | +function get_include_contents($filename) |
| 11 | +{ |
| 12 | + if (is_file($filename)) { |
| 13 | + ob_start(); |
| 14 | + include $filename; |
| 15 | + return ob_get_clean(); |
| 16 | + } |
| 17 | + return false; |
| 18 | +} |
| 19 | + |
| 20 | +$feed = new atomfeed(); |
| 21 | + |
| 22 | +$feed->title = "j0's blog"; |
| 23 | +$feed->id_uri = $host . "/blog"; |
| 24 | +$feed->feed_uri = $host . "/feed"; |
| 25 | + |
| 26 | +$feed->logo_uri = $host . "/static/j0site-pfp.png"; |
| 27 | +$feed-> addauthor( "Jo Null", "[email protected]", "https://j0.lol/", "author"); |
| 28 | + |
| 29 | +foreach ($posts as $slug => $post) { |
| 30 | + $parser = new MarkdownExtra(); |
| 31 | + $content = $parser->transform( |
| 32 | + file_get_contents("./posts/" . $slug . ".md") |
| 33 | + ); |
| 34 | + |
| 35 | + $feed->addentry( |
| 36 | + $host . "/blog/" . $slug, |
| 37 | + $post["title"], |
| 38 | + $post["date"]->getTimestamp(), |
| 39 | + "Jo Null", |
| 40 | + $content |
| 41 | + ); |
| 42 | +} |
| 43 | + |
| 44 | +//set the content-type |
| 45 | +header("content-type: application/atom+xml"); |
| 46 | + |
| 47 | +//render and output the generated feed |
| 48 | +echo $feed->render(); |
| 49 | + |
| 50 | +// $feed = Feed::create([ |
| 51 | +// "link" => $host . "/blog", |
| 52 | +// "authors" => "Jo Null", |
| 53 | +// "title" => 'j0\'s blog', |
| 54 | +// "feed" => $host . "/feed.xml", |
| 55 | +// "description" => "A series of posts by j0", |
| 56 | +// "updated" => $posts_updated->format(DATE_ATOM), |
| 57 | +// ]); |
| 58 | + |
| 59 | +// foreach ($posts as $slug => $post) { |
| 60 | +// $parser = new MarkdownExtra(); |
| 61 | +// $content = $parser->transform( |
| 62 | +// file_get_contents("./posts/" . $slug . ".md") |
| 63 | +// ); |
| 64 | + |
| 65 | +// $feed->entry([ |
| 66 | +// "title" => $post["title"], |
| 67 | +// "published" => $post["date"]->format(DATE_ATOM), |
| 68 | +// "link" => $host . "/blog/" . $slug, |
| 69 | +// "summary" => $post["subtitle"] ?? "A post by j0", |
| 70 | +// "content" => $content, |
| 71 | +// ]); |
| 72 | +// } |
| 73 | + |
| 74 | +// echo $feed->asAtom(); |
0 commit comments