Matching with regex instead of globbing.
This commit is contained in:
parent
bb457c2fc3
commit
be986e8be3
|
@ -1,4 +0,0 @@
|
||||||
RewriteEngine on
|
|
||||||
RewriteBase /~j3parker/
|
|
||||||
RewriteRule ^pub/(.*) - [L]
|
|
||||||
RewriteRule ^(.*) bin/web [L]
|
|
|
@ -8,6 +8,6 @@ const bool nav_tree_vert = false;
|
||||||
string[string] handlers;
|
string[string] handlers;
|
||||||
|
|
||||||
void init_handlers() {
|
void init_handlers() {
|
||||||
handlers["*.md"] = "contrib/Markdown.pl";
|
handlers["(.*).md"] = "contrib/Markdown.pl";
|
||||||
handlers["changelog"] = "changelog.sh";
|
handlers["changelog"] = "changelog.sh";
|
||||||
}
|
}
|
||||||
|
|
14
src/web.d
14
src/web.d
|
@ -1,5 +1,5 @@
|
||||||
//#!/usr/bin/rdmd
|
//#!/usr/bin/rdmd
|
||||||
import std.stdio, std.path, std.process, std.file, std.array, std.string, std.algorithm, std.datetime, std.ascii;
|
import std.stdio, std.path, std.process, std.file, std.array, std.string, std.algorithm, std.datetime, std.ascii, std.regex;
|
||||||
import config;
|
import config;
|
||||||
|
|
||||||
string dweb_root;
|
string dweb_root;
|
||||||
|
@ -92,12 +92,14 @@ 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 glob, string h; handlers) {
|
foreach (string rstr, string h; handlers) {
|
||||||
if (globMatch(url, glob)) {
|
try {
|
||||||
|
if (match(url, regex(rstr, ""))) {
|
||||||
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ url));
|
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ url));
|
||||||
html_pop("</div>");
|
html_pop("</div>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (std.regex.RegexException re) { continue; }
|
||||||
}
|
}
|
||||||
// if that failed, see if we can handle the file
|
// if that failed, see if we can handle the file
|
||||||
if (url == "" ? true : url[$-1] == '/') url ~= "index";
|
if (url == "" ? true : url[$-1] == '/') url ~= "index";
|
||||||
|
@ -105,12 +107,14 @@ 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 glob, string h; handlers) {
|
foreach (string rstr, string h; handlers) {
|
||||||
if (globMatch(name, glob)) {
|
try {
|
||||||
|
if (match(name, regex(rstr, ""))) {
|
||||||
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ f));
|
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ f));
|
||||||
html_pop("</div>");
|
html_pop("</div>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} catch (std.regex.RegexException re) { continue; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue