Matching with regex instead of globbing.

master
Luqman Aden 11 years ago
parent bb457c2fc3
commit be986e8be3
  1. 4
      .htaccess
  2. 2
      src/config.d.sample
  3. 30
      src/web.d

@ -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;
void init_handlers() {
handlers["*.md"] = "contrib/Markdown.pl";
handlers["(.*).md"] = "contrib/Markdown.pl";
handlers["changelog"] = "changelog.sh";
}

@ -1,5 +1,5 @@
//#!/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;
string dweb_root;
@ -92,12 +92,14 @@ bool dirExists(string path) { try { if (isDir(path)) return true; else return
void do_content(string url) {
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
foreach (string glob, string h; handlers) {
if (globMatch(url, glob)) {
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ url));
html_pop("</div>");
return;
}
foreach (string rstr, string h; handlers) {
try {
if (match(url, regex(rstr, ""))) {
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ url));
html_pop("</div>");
return;
}
} catch (std.regex.RegexException re) { continue; }
}
// if that failed, see if we can handle the file
if (url == "" ? true : url[$-1] == '/') url ~= "index";
@ -105,12 +107,14 @@ 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 glob, string h; handlers) {
if (globMatch(name, glob)) {
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ f));
html_pop("</div>");
return;
}
foreach (string rstr, string h; handlers) {
try {
if (match(name, regex(rstr, ""))) {
html(shell(dweb_root ~ "/bin/" ~ h ~ " " ~ f));
html_pop("</div>");
return;
}
} catch (std.regex.RegexException re) { continue; }
}
}
}

Loading…
Cancel
Save