Add more support for internationalisation, style changes

This commit is contained in:
Chris Josten 2021-03-11 17:22:40 +01:00
parent 5506163cba
commit 46bea4fa58
16 changed files with 125 additions and 1461 deletions

View file

@ -169,17 +169,6 @@ public:
//getSingle!(Page, "pages/page.dt")(pages, req, res);
mixin(singleResponseMixin("pages", "pages/page.dt"));
}
/**
* Template method for fetching a single page for a subclass of page.
* Params:
* T = the data structure/class to be passed as template parameter. Must have a slug parameter.
* templ = The template to use when rendering.
* array = An associative array where the keys are slugs for parameters and the values the template parameter.
* req = The server request to consume. Assumes there is an slug parameter.
* res = The server response to write to.
*
*/
}
/**

View file

@ -88,6 +88,7 @@ class Page {
this.m_slug = this.m_title;
infof("%s does not have a slug. Using %s", this.m_name, this.m_slug);
}
this.m_language = headerNode.getOr!string("language", "unknown");
hasCalledSuper = true;
}
@ -102,7 +103,8 @@ class Page {
public static string parseMarkdown(string source, int shiftHeader = 0) {
string[] args = ["pandoc",
"-f", "markdown",
"-t", "html"];
"-t", "html",
"--lua-filter", "defaultClasses.lua"];
if (shiftHeader != 0) args ~= "--shift-heading-level-by=" ~ to!string(shiftHeader);
@ -117,7 +119,7 @@ class Page {
while ((line = pandoc.stdout.readln()) !is null) {
result ~= line;
debug {
logf("Pandoc stdout: %s", line);
//logf("Pandoc stdout: %s", line);
}
}

View file

@ -1,5 +1,6 @@
import std.array;
import std.algorithm;
import std.typecons;
import dyaml;
import vibe.vibe;
@ -12,6 +13,7 @@ import utils;
* Represents a project, like an unfinished application
*/
class Project : Page {
alias Link= Tuple!(string, "name", string, "url");
protected immutable string PROJECT_ICON_DIR = IMG_DIR ~ "projects/icons/";
protected immutable string PROJECT_IMAGE_DIR = IMG_DIR ~ "projects/images/";
protected string m_state;
@ -20,7 +22,7 @@ class Project : Page {
protected string m_icon;
protected string[] m_images;
protected string m_description;
protected string m_sourceCode;
protected Link[] m_sourceCode = [];
/**
* Creates a project from a file
@ -39,7 +41,13 @@ class Project : Page {
this.m_images = headerNode.getArray!string("images", [])
.map!(x => PROJECT_IMAGE_DIR ~ x).array;
this.m_description = headerNode.getOr!string("description", "<no description>");
this.m_sourceCode = headerNode.getOr!string("sourceCode", null);
if ("sourceCode" in headerNode) {
m_sourceCode.reserve(headerNode.length);
foreach(Node node; headerNode["sourceCode"]) {
m_sourceCode ~= tuple!("name", "url")(node.getOr!string("name", "link"),
node.getOr!string("url", "#"));
}
}
}
@property string state() { return m_state; }
@ -48,6 +56,6 @@ class Project : Page {
@property string icon() { return m_icon; }
@property string[] images() { return m_images; }
@property string description() { return m_description; }
@property string sourceCode() { return m_sourceCode; }
@property Link[] sourceCode() { return m_sourceCode; }
}

View file

@ -9,6 +9,9 @@ import vibe.d;
import app;
import page;
/**
* Loads pages into memory and sets up a "watcher" to watch a directory for file changes.
*/
void initPages(T, string sortPred)(ref T[string] array, ref T*[] sortedRange, const string directory) {
bool addPage(string path) {
@ -86,7 +89,7 @@ void initPages(T, string sortPred)(ref T[string] array, ref T*[] sortedRange, co
}
}
}
logf("Modified %s", newPage.slug);
logf("%s modified: %s", typeid(T).stringof, newPage.slug);
array[newPage.slug] = newPage;
} catch(page.ArticleParseException e) {
warningf("Could not parse %s", change.path.toString());