Merge pull request #1 from luqmana/master

404 Error Index Fix + Set git to ignore .htaccess and config.d
This commit is contained in:
Jacob Parker 2012-02-23 10:17:45 -08:00
commit 783081d030
6 changed files with 62 additions and 7 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
pub/* pub/*
srv/* srv/*
bin/web bin/web
.htaccess
src/config.d

View File

@ -1,4 +0,0 @@
RewriteEngine on
RewriteBase /~j3parker/
RewriteRule ^pub/(.*) - [L]
RewriteRule ^(.*) /users/j3parker/www/bin/web [L]

53
README.md Normal file
View File

@ -0,0 +1,53 @@
dweb - A simple website written in D
=====
dweb is a simple website framework based off the [werc][werc] software.
Its principles are:
- Database free, uses files and directories instead.
- Written using the D programming language.
- Minimize tedious work: eg., no need to ever write HTML, use markdown instead.
- Very minimalist yet extensible codebase. Handlers for special things should be easy to add.
It was created because werc was annoying to deploy on UW Computer Science Club's Apache setup and because [Not Invented Here](http://en.wikipedia.org/wiki/Not_Invented_Here).
[werc]:http://werc.cat-v.org/
[md]:http://daringfireball.net/projects/markdown
Install Guide
------
You will need:
- An HTTP server with CGI support.
- The D compiler.
Extract the contents into the location you want to serve webpages from. Create <code>$DWEB\_ROOT/.htaccess</code> and <code>$DWEB\_ROOT/src/config.d</code> by copying the provided sample files. Then edit the following files:
- <code>$DWEB_ROOT/.htaccess</code>: make the paths work for your setup.
- <code>$DWEB_ROOT/src/config.d</code>: change these strings as necessary.
- <code>$DWEB_ROOT/src/web.d</code>: this is the main web code.
- <code>$DWEB_ROOT/pub/</code>: static content goes here.
- <code>$DWEB_ROOT/srv/</code>: directories, markdown webpages etc. go in here.
- <code>$DWEB_ROOT/bin/</code>: custom handlers go here.
Run <code>build</code> in <code>$DWEB_ROOT/src</code> to recompile the website software.
Source
--------
You can get the source code on [github](https://github.com/j3parker/dweb) or by running
git clone git://github.com/j3parker/dweb.git
Contact
--------
For questions, suggestions, bug reports and contributing patches email [j3parker](mailto:j3parker@csclub.uwaterloo.ca)
License
-------
Public domain.
Credits
-------
The idea and css stolen from [werc][werc]. This page itself also plagarised.
Thanks to John Gruber for the [Markdown.pl][md] script.

4
htaccess-sample Normal file
View File

@ -0,0 +1,4 @@
RewriteEngine on
RewriteBase /
RewriteRule ^pub/(.*) - [L]
RewriteRule ^(.*) bin/web [L]

View File

@ -1,4 +1,4 @@
const string url_root = "/~j3parker/"; const string url_root = "/";
const string site_title = "This is a Title"; const string site_title = "This is a Title";
const string site_subtitle = "but this is a subtitle"; const string site_subtitle = "but this is a subtitle";

View File

@ -101,7 +101,7 @@ void do_content(string url) {
} }
} }
// if that failed, see if we can handle the file // if that failed, see if we can handle the file
if (url == "" ? false : url[$-1] == '/') url ~= "index"; if (url == "" ? true : url[$-1] == '/') url ~= "index";
foreach (f; array(map!"a.name"(dirEntries(dirName(dweb_root ~ "/srv/" ~ url), SpanMode.shallow)))) { foreach (f; array(map!"a.name"(dirEntries(dirName(dweb_root ~ "/srv/" ~ url), SpanMode.shallow)))) {
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;
@ -146,7 +146,7 @@ void main(string[] args) {
html("<!DOCTYPE html>"); html("<!DOCTYPE html>");
html_push("<html>\n"); html_push("<html>\n");
string url = getenv("SCRIPT_URL")[url_root.length..$]; string url = getenv("REQUEST_URI")[url_root.length..$];
if (evil(url)) { html ("bad url."); return; } if (evil(url)) { html ("bad url."); return; }
string pagename = baseName(url); string pagename = baseName(url);