Skip to content

Commit 0af885a

Browse files
committed
Add RSS
1 parent cba05cf commit 0af885a

File tree

9 files changed

+1364
-13
lines changed

9 files changed

+1364
-13
lines changed

app/blog-index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
printf("<li><a href=\"%s\">%s</a> &bullet; Posted on %s</li>",
2424
$router->generate("blog-post", ['post_slug' => "$slug"]),
2525
$item["title"],
26-
$item["date"]
26+
$item["date"]->format("l jS \of F, Y")
2727
);
2828
} catch (Exception $e) {
2929
echo $e;

app/blog-post.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
<main>
99

1010
<?php
11+
use Aeon\Calendar\Gregorian\DateTime;
12+
1113
global $posts, $post_slug;
1214

1315
$meta = $posts[$post_slug];
16+
$date = $meta["date"];
1417

15-
printf(<<<END
18+
printf(
19+
<<<END
1620
<h1>%s</h1>
1721
%s
1822
<p>Posted on %s</p>
@@ -21,7 +25,7 @@
2125
(key_exists("subtitle", $meta))
2226
? '<p><em>' . $meta["subtitle"] . '</em></p>'
2327
: "",
24-
$meta["date"]);
28+
$date->format("l jS \of F, Y"));
2529
?>
2630

2731
<hr>

app/feed.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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();

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"require": {
33
"altorouter/altorouter": "^2.0",
4-
"michelf/php-markdown": "^2.0"
4+
"michelf/php-markdown": "^2.0",
5+
"nesbot/carbon": "^3.8"
56
}
67
}

0 commit comments

Comments
 (0)