diff --git a/src/config.d.sample b/src/config.d.sample index 2ecce45..d4eba96 100644 --- a/src/config.d.sample +++ b/src/config.d.sample @@ -1,3 +1,5 @@ +import std.regex; + const string url_root = "/"; const string site_title = "This is a Title"; @@ -5,9 +7,17 @@ const string site_subtitle = "but this is a subtitle"; const bool nav_tree_vert = false; -string[string] handlers; +string[StaticRegex!char] handlers; void init_handlers() { - handlers["(.*).md"] = "contrib/Markdown.pl"; - handlers["changelog"] = "changelog.sh"; + handler!("(.*).md").add("contrib/Markdown.pl"); + handler!("changelog").add("changelog.sh"); +} + +template handler(string pattern) { + void add(string h) { + try { + handlers[ctRegex!(pattern)] = h; + } catch (std.regex.Exception re) { return; } + } } diff --git a/src/web.d b/src/web.d index b2e17b5..e0b2073 100755 --- a/src/web.d +++ b/src/web.d @@ -92,9 +92,9 @@ bool dirExists(string path) { try { if (isDir(path)) return true; else return void do_content(string url) { html_push("
"); // first, see if we have something that wants to handle url outright - foreach (string rstr, string h; handlers) { + foreach (StaticRegex!char reg, string h; handlers) { try { - if (match(url, regex(rstr, ""))) { + if (match(url, reg)) { html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ url)); html_pop("
"); return; @@ -107,9 +107,9 @@ void do_content(string url) { if (isDir(f)) continue; string name = baseName(f); name = name[0] == '@' ? name[1..$] : name; if (stripExtension(name) == baseName(url)) { - foreach (string rstr, string h; handlers) { + foreach (StaticRegex!char reg, string h; handlers) { try { - if (match(name, regex(rstr, ""))) { + if (match(name, reg)) { html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ f)); html_pop(""); return;