atom: add atom feed to website for posts
This commit is contained in:
parent
63f177475b
commit
0e7aa0451f
|
@ -14,6 +14,14 @@ function get_default_code_class(meta)
|
|||
end
|
||||
end
|
||||
|
||||
function make_image_url_absolute (img)
|
||||
if img.src:sub(1,1) == '/' then
|
||||
img.src = os.getenv 'WEBROOT' .. img.src
|
||||
end
|
||||
return img
|
||||
end
|
||||
|
||||
return {{Meta = get_default_code_class},
|
||||
{Code = add_default_code_class},
|
||||
{CodeBlock = add_default_code_class}}
|
||||
{CodeBlock = add_default_code_class},
|
||||
{Image = make_image_url_absolute}}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -20,3 +20,9 @@ msgid "template.page.copyright"
|
|||
msgstr "© Chris Josten, 2024. If not specified otherwise, all content on this "
|
||||
"website is <a rel=\"license\" href=\"https://creativecommons.org/licenses/by/4.0/\">"
|
||||
"licensed under the CC-BY 4.0</a>"
|
||||
|
||||
msgid "template.feed.title"
|
||||
msgstr "%s | Chris's website"
|
||||
|
||||
msgid "template.feed.posts.title"
|
||||
msgstr "Posts"
|
||||
|
|
|
@ -32,3 +32,9 @@ msgstr "Contact"
|
|||
msgid "template.page.copyright"
|
||||
msgstr "© Chris Josten, 2024. Tenzij anders vermeld staat, valt alle inhoud op deze webstek "
|
||||
"<a rel=\"license\" href=\"https://creativecommons.org/licenses/by/4.0/\"> onder de CC-BY 4.0</a>"
|
||||
|
||||
msgid "template.feed.title"
|
||||
msgstr "%s | Chris z'n webstekkie"
|
||||
|
||||
msgid "template.feed.posts.title"
|
||||
msgstr "Berichten"
|
||||
|
|
|
@ -1,2 +1,28 @@
|
|||
msgid "page.header-bottom-text"
|
||||
msgstr ""
|
||||
msgid "template.page.name"
|
||||
msgstr "Chris's website"
|
||||
|
||||
msgid "template.page.html_language"
|
||||
msgstr "en-GB"
|
||||
|
||||
msgid "template.menu.home"
|
||||
msgstr "Home"
|
||||
|
||||
msgid "template.menu.posts"
|
||||
msgstr "Posts"
|
||||
|
||||
msgid "template.menu.projects"
|
||||
msgstr "Projects"
|
||||
|
||||
msgid "template.menu.contact"
|
||||
msgstr "Contact"
|
||||
|
||||
msgid "template.page.copyright"
|
||||
msgstr "© Chris Josten, 2024. If not specified otherwise, all content on this "
|
||||
"website is <a rel=\"license\" href=\"https://creativecommons.org/licenses/by/4.0/\">"
|
||||
"licensed under the CC-BY 4.0</a>"
|
||||
|
||||
msgid "template.feed.title"
|
||||
msgstr "%s | Chris's website"
|
||||
|
||||
msgid "template.feed.posts.title"
|
||||
msgstr "Posts"
|
||||
|
|
|
@ -6,6 +6,7 @@ html(prefix="og: http://ogp.me/ns#")
|
|||
//- Kick off loading the css as fast as possible
|
||||
meta(name="viewport", content="width=device-width; initial-scale=1")
|
||||
link(rel="stylesheet", href="/static/style/base.css")
|
||||
link(rel="alternate", href="/feeds/posts.atom", type="application/atom+xml", title=trWeb("template.feed.title").format(trWeb("template.feed.posts.title")))
|
||||
|
||||
- string page_image = "/static/img/logo.png";
|
||||
- string page_title;
|
||||
|
|
Loading…
Reference in a new issue