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

@ -9,5 +9,6 @@
}, },
"description": "A blog based on Markdown and JSON", "description": "A blog based on Markdown and JSON",
"license": "AGPLv3", "license": "AGPLv3",
"name": "mijnblog" "name": "mijnblog",
"stringImportPaths": ["views", "translations"]
} }

View file

@ -102,47 +102,67 @@ void getSingle(T, string templ)(ref T[string] array, HTTPServerRequest req, HTTP
} }
} }
/** struct TranslationContext {
* Generates response for /posts/:slug and /palen/:slug. import std.typetuple;
*/ enum enforceExistingKeys = true;
void articleGetSingle(HTTPServerRequest req, HTTPServerResponse res) { alias languages = TypeTuple!("en_GB", "nl_NL");
getSingle!(Article, "pages/article.dt")(articles, req, res); mixin translationModule!"mijnblog";
} }
/** @translationContext!TranslationContext
* Generates response for /posts and /palen class MijnBlog {
*/ /**
void articleGetOverview(HTTPServerRequest req, HTTPServerResponse res) { * Generates response for /posts/:slug and /palen/:slug.
addCachingHeader(res); */
render!("pages/article-list.dt", articleList)(res); @path("/posts/:slug")
} void getArticleSingle(string _slug, HTTPServerRequest req, HTTPServerResponse res) {
getSingle!(Article, "pages/article.dt")(articles, req, 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");
} }
getSingle!(Page, "pages/page.dt")(pages, req, res);
}
/** /**
* Generate response for a project page * Generates response for /posts and /palen
*/ */
void projectGet(HTTPServerRequest req, HTTPServerResponse res) { @path("/posts/")
res.headers["Cache-Control"] = "public"; void getArticleOverview(HTTPServerRequest req, HTTPServerResponse res) {
getSingle!(Project, "pages/project.dt")(projects, req, 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); fSettings.maxAge = days(16);
URLRouter router = new URLRouter; 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("/palen/:slug", &articleGetSingle);
router.get("/posts/", &articleGetOverview); router.get("/posts/", &articleGetOverview);
router.get("/palen/", &articleGetOverview); router.get("/palen/", &articleGetOverview);
router.get("/projects/", &projectGetOverview); router.get("/projects/", &projectGetOverview);
router.get("/projects/:slug", &projectGet); router.get("/projects/:slug", &projectGet);
router.get("/projecten/:slug", &projectGet); router.get("/projecten/:slug", &projectGet);
router.get("/static/*", serveStaticFiles("./public/", fSettings));
router.get("/:slug", &pageGet); router.get("/:slug", &pageGet);
router.get("/", &pageGet); router.get("/", &pageGet);*/
listenHTTP(settings, router); listenHTTP(settings, router);

View file

@ -2,7 +2,7 @@
* Constants which are passed to templates while rendering. * Constants which are passed to templates while rendering.
*/ */
class Constants { 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 SITE_URL = "https://chris.netsoj.nl";
public static immutable string COPYRIGHT = "© Chris Josten, 2020"; public static immutable string COPYRIGHT = "© Chris Josten, 2020";
} }

View file

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

View file

@ -0,0 +1,2 @@
msgid "page.header-bottom-text"
msgstr "Chris's website"

BIN
translations/mijnblog.nl.mo Normal file

Binary file not shown.

View file

@ -0,0 +1,15 @@
msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: nl\n"
"X-Generator: Poedit 2.3.1\n"
msgid "Chris's website"
msgstr "Chris z'n webstekkie"

View file

@ -0,0 +1,2 @@
msgid "page.header-bottom-text"
msgstr ""

View file

@ -14,10 +14,10 @@ html(prefix="og: http://ogp.me/ns#")
block meta_data block meta_data
- if (page_title !is null) - if (page_title !is null)
title #{page_title} - Chris Netsoj.nl title& #{page_title} - #{Constants.SITE_NAME}
meta(name="og:title", content=page_title) meta(name="og:title", content=page_title)
- else - else
title Chris Netsoj.nl title& #{Constants.SITE_NAME}
meta(name="og:site_name", content=Constants.SITE_NAME) meta(name="og:site_name", content=Constants.SITE_NAME)
- if (page_image !is null) - if (page_image !is null)
@ -45,7 +45,7 @@ html(prefix="og: http://ogp.me/ns#")
section.header-navigation section.header-navigation
header header
img.logo(src="/static/img/logo.png", alt="The logo of the website: the letter C drawn in an unprofessional manner with wobbly eyes on put on top") img.logo(src="/static/img/logo.png", alt="The logo of the website: the letter C drawn in an unprofessional manner with wobbly eyes on put on top")
p Chris's webstekkie p& Chris's website
nav nav
ul ul
- menuItem("home", "/"); - menuItem("home", "/");