WIP: translation (but it ain't broken)

This commit is contained in:
Chris Josten 2020-06-28 00:11:50 +02:00
parent 8d2feaa76b
commit 9f879be71b
9 changed files with 88 additions and 45 deletions

View file

@ -102,47 +102,67 @@ void getSingle(T, string templ)(ref T[string] array, HTTPServerRequest req, HTTP
}
}
/**
* Generates response for /posts/:slug and /palen/:slug.
*/
void articleGetSingle(HTTPServerRequest req, HTTPServerResponse res) {
getSingle!(Article, "pages/article.dt")(articles, req, res);
struct TranslationContext {
import std.typetuple;
enum enforceExistingKeys = true;
alias languages = TypeTuple!("en_GB", "nl_NL");
mixin translationModule!"mijnblog";
}
/**
* Generates response for /posts and /palen
*/
void articleGetOverview(HTTPServerRequest req, HTTPServerResponse res) {
addCachingHeader(res);
render!("pages/article-list.dt", articleList)(res);
}
/**
* Generates response for /projects and /projecten
*/
void projectGetOverview(HTTPServerRequest req, HTTPServerResponse res) {
addCachingHeader(res);
render!("pages/project-list.dt", projectList)(res);
}
/**
* Generate response for a page
*/
void pageGet(HTTPServerRequest req, HTTPServerResponse res) {
addCachingHeader(res);
// If no slug is supplied, it will be adjusted to "index"
if (("slug" in req.params) is null) {
req.params.addField("slug", "index");
@translationContext!TranslationContext
class MijnBlog {
/**
* Generates response for /posts/:slug and /palen/:slug.
*/
@path("/posts/:slug")
void getArticleSingle(string _slug, HTTPServerRequest req, HTTPServerResponse res) {
getSingle!(Article, "pages/article.dt")(articles, req, res);
}
getSingle!(Page, "pages/page.dt")(pages, req, res);
}
/**
* Generate response for a project page
*/
void projectGet(HTTPServerRequest req, HTTPServerResponse res) {
res.headers["Cache-Control"] = "public";
getSingle!(Project, "pages/project.dt")(projects, req, res);
/**
* Generates response for /posts and /palen
*/
@path("/posts/")
void getArticleOverview(HTTPServerRequest req, HTTPServerResponse res) {
addCachingHeader(res);
render!("pages/article-list.dt", articleList)(res);
}
/**
* Generates response for /projects and /projecten
*/
@path("/projects/")
void getProjectOverview(HTTPServerRequest req, HTTPServerResponse res) {
addCachingHeader(res);
render!("pages/project-list.dt", projectList)(res);
}
/**
* Generate response for a project page
*/
@path("/projects/:slug")
void getProject(HTTPServerRequest req, HTTPServerResponse res) {
res.headers["Cache-Control"] = "public";
getSingle!(Project, "pages/project.dt")(projects, req, res);
}
/**
* Generate response for a page
*/
@path("/:slug")
void getPage(HTTPServerRequest req, HTTPServerResponse res) {
addCachingHeader(res);
getSingle!(Page, "pages/page.dt")(pages, req, res);
}
@path("/")
void getIndexPage(HTTPServerRequest req, HTTPServerResponse res) {
addCachingHeader(res);
// If no slug is supplied, it will be adjusted to "index"
req.params.addField("slug", "index");
getSingle!(Page, "pages/page.dt")(pages, req, res);
}
}
/**
@ -167,16 +187,17 @@ void main() {
fSettings.maxAge = days(16);
URLRouter router = new URLRouter;
router.get("/posts/:slug", &articleGetSingle);
router.get("/static/*", serveStaticFiles("./public/", fSettings));
router.registerWebInterface(new MijnBlog);
/*router.get("/posts/:slug", &articleGetSingle);
router.get("/palen/:slug", &articleGetSingle);
router.get("/posts/", &articleGetOverview);
router.get("/palen/", &articleGetOverview);
router.get("/projects/", &projectGetOverview);
router.get("/projects/:slug", &projectGet);
router.get("/projecten/:slug", &projectGet);
router.get("/static/*", serveStaticFiles("./public/", fSettings));
router.get("/:slug", &pageGet);
router.get("/", &pageGet);
router.get("/", &pageGet);*/
listenHTTP(settings, router);

View file

@ -2,7 +2,7 @@
* Constants which are passed to templates while rendering.
*/
class Constants {
public static immutable string SITE_NAME = "Chris Netsoj.nl";
public static immutable string SITE_NAME = "Chris Josten's site";
public static immutable string SITE_URL = "https://chris.netsoj.nl";
public static immutable string COPYRIGHT = "© Chris Josten, 2020";
}

View file

@ -37,6 +37,7 @@ class Page {
protected string m_content;
protected string m_contentSource;
protected bool m_hidden;
protected string m_language;
/**
@ -130,4 +131,5 @@ class Page {
@property string content() { return m_content; }
@property string contentSource() { return m_contentSource; }
@property bool isHidden() { return m_hidden; }
@property string language() { return m_language; }
}