atom: add atom feed to website for posts
This commit is contained in:
parent
63f177475b
commit
0e7aa0451f
8 changed files with 115 additions and 6 deletions
|
|
@ -1,8 +1,10 @@
|
|||
/**
|
||||
* Constants which are passed to templates while rendering.
|
||||
*/
|
||||
class Constants {
|
||||
struct Constants {
|
||||
public static immutable string SITE_NAME = "Chris Josten's site";
|
||||
public static immutable string SITE_HOST = "chris.netsoj.nl";
|
||||
public static immutable string SITE_URL = "https://chris.netsoj.nl";
|
||||
public static immutable string SITE_AUTHOR = "Chris Josten";
|
||||
public static immutable string COPYRIGHT = "© Chris Josten, 2020";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
import std.algorithm : map, maxElement;
|
||||
import std.format : format;
|
||||
import std.string: join;
|
||||
|
||||
import vibe.d;
|
||||
|
||||
import cache;
|
||||
import constants;
|
||||
import article;
|
||||
import page;
|
||||
import project;
|
||||
|
|
@ -141,7 +146,59 @@ public:
|
|||
// If no slug is supplied, it will be adjusted to "index"
|
||||
req.params.addField("slug", "index");
|
||||
mixin(singleResponseMixin("pages", "pages/page.dt"));
|
||||
}
|
||||
}
|
||||
|
||||
@path("/feeds/posts.atom")
|
||||
void getPostFeed(HTTPServerRequest req, HTTPServerResponse res) {
|
||||
Article[] articleList = articles.sortedList;
|
||||
|
||||
DateTime lastUpdated = articleList.map!"a.firstPublished()".maxElement;
|
||||
|
||||
string response = q"EOS
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<updated>%s</updated>
|
||||
<title>%s</title>
|
||||
<icon>%s</icon>
|
||||
<link href="%s/feeds/posts.atom" rel="self" />
|
||||
<link href="%s" />
|
||||
<id>urn:uuid:036f1087-7fcd-466d-866d-78a0c60038cd</id>
|
||||
<author><name>%s</name></author>
|
||||
%s
|
||||
</feed>
|
||||
EOS"
|
||||
.format(
|
||||
lastUpdated.toISOExtString() ~ "Z",
|
||||
trWeb("template.feed.title").format(trWeb("template.feed.posts.title")),
|
||||
Constants.SITE_URL ~ "/static/img/logo.png",
|
||||
Constants.SITE_URL,
|
||||
Constants.SITE_URL,
|
||||
Constants.SITE_AUTHOR,
|
||||
articleList.map!((article) {
|
||||
return q"EOS
|
||||
<entry>
|
||||
<title>%s</title>
|
||||
<link href="%s" />
|
||||
<id>%s</id>
|
||||
<published>%s</published>
|
||||
<updated>%s</updated>
|
||||
<summary>%s</summary>
|
||||
<content type="html">%s</content>
|
||||
</entry>
|
||||
|
||||
EOS"
|
||||
.format(article.title,
|
||||
Constants.SITE_URL ~ "/posts/" ~ article.slug,
|
||||
"tag:" ~ Constants.SITE_HOST ~ ",2024:blog:posts:" ~ article.slug,
|
||||
article.firstPublished().toISOExtString() ~ "Z",
|
||||
article.updated().toISOExtString() ~ "Z",
|
||||
article.excerpt(),
|
||||
htmlEscape(article.content())
|
||||
);
|
||||
}).join()
|
||||
);
|
||||
res.writeBody(response, "application/atom+xml");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import std.stdio;
|
|||
import dyaml;
|
||||
import vibe.vibe;
|
||||
|
||||
import constants;
|
||||
import utils;
|
||||
|
||||
@safe:
|
||||
|
|
@ -107,10 +108,12 @@ class Page {
|
|||
"-f", "markdown",
|
||||
"-t", "html",
|
||||
"--lua-filter", "defaultClasses.lua"];
|
||||
string[string] env;
|
||||
env["WEBROOT"] = Constants.SITE_URL;
|
||||
|
||||
if (shiftHeader != 0) args ~= "--shift-heading-level-by=" ~ to!string(shiftHeader);
|
||||
|
||||
ProcessPipes pandoc = pipeProcess(args);
|
||||
ProcessPipes pandoc = pipeProcess(args, Redirect.all, env);
|
||||
pandoc.stdin.write(source);
|
||||
pandoc.stdin.writeln();
|
||||
pandoc.stdin.flush();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue