Handlers now use static regex at compile-time.
This commit is contained in:
parent
be986e8be3
commit
259b9f6476
|
@ -1,3 +1,5 @@
|
||||||
|
import std.regex;
|
||||||
|
|
||||||
const string url_root = "/";
|
const string url_root = "/";
|
||||||
|
|
||||||
const string site_title = "This is a Title";
|
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;
|
const bool nav_tree_vert = false;
|
||||||
|
|
||||||
string[string] handlers;
|
string[StaticRegex!char] handlers;
|
||||||
|
|
||||||
void init_handlers() {
|
void init_handlers() {
|
||||||
handlers["(.*).md"] = "contrib/Markdown.pl";
|
handler!("(.*).md").add("contrib/Markdown.pl");
|
||||||
handlers["changelog"] = "changelog.sh";
|
handler!("changelog").add("changelog.sh");
|
||||||
|
}
|
||||||
|
|
||||||
|
template handler(string pattern) {
|
||||||
|
void add(string h) {
|
||||||
|
try {
|
||||||
|
handlers[ctRegex!(pattern)] = h;
|
||||||
|
} catch (std.regex.Exception re) { return; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,9 +92,9 @@ bool dirExists(string path) { try { if (isDir(path)) return true; else return
|
||||||
void do_content(string url) {
|
void do_content(string url) {
|
||||||
html_push("<div id=\"main-copy\"" ~ (nav_tree_vert? " class=\"main-copy-side-bar\"" : "") ~ ">");
|
html_push("<div id=\"main-copy\"" ~ (nav_tree_vert? " class=\"main-copy-side-bar\"" : "") ~ ">");
|
||||||
// first, see if we have something that wants to handle url outright
|
// 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 {
|
try {
|
||||||
if (match(url, regex(rstr, ""))) {
|
if (match(url, reg)) {
|
||||||
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ url));
|
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ url));
|
||||||
html_pop("</div>");
|
html_pop("</div>");
|
||||||
return;
|
return;
|
||||||
|
@ -107,9 +107,9 @@ void do_content(string url) {
|
||||||
if (isDir(f)) continue;
|
if (isDir(f)) continue;
|
||||||
string name = baseName(f); name = name[0] == '@' ? name[1..$] : name;
|
string name = baseName(f); name = name[0] == '@' ? name[1..$] : name;
|
||||||
if (stripExtension(name) == baseName(url)) {
|
if (stripExtension(name) == baseName(url)) {
|
||||||
foreach (string rstr, string h; handlers) {
|
foreach (StaticRegex!char reg, string h; handlers) {
|
||||||
try {
|
try {
|
||||||
if (match(name, regex(rstr, ""))) {
|
if (match(name, reg)) {
|
||||||
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ f));
|
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ f));
|
||||||
html_pop("</div>");
|
html_pop("</div>");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue