]> Pileus Git - site/commitdiff
Add status codes
authorAndy Spencer <andy753421@gmail.com>
Mon, 24 Dec 2012 20:52:52 +0000 (20:52 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 24 Dec 2012 20:52:52 +0000 (20:52 +0000)
src/html.h
src/main.c
theme/html.ct

index b3a5d72d96cc937568871bc4e2336f671605baf9..a170dff1c5f191710643fb8690b5f13c22993d67 100644 (file)
@@ -23,6 +23,7 @@ struct page_t {
        char     *title; // title tag
        char     *keys;  // meta keywords tag, or NULL
        char     *desc;  // meta description tag, or NULL
+       char     *error; // http status
        char     *text;  // unfiltered text
        char     *html;  // generated html
 };
@@ -44,5 +45,5 @@ void print_link(char *path, char *name, int cur);
 void print_menu(menu_t *menu, int first, int last);
 
 /* Global functions */
-void print_header(void);
+void print_header(page_t *page);
 void print_page(page_t *page, menu_t *menu);
index 8cfc49ca52378a3a48afd6c357dc166e8ada3d0f..71f8b40254e9dfc4845772d90e5bf30a9a81a62d 100644 (file)
@@ -247,13 +247,15 @@ static void do_regular(page_t *page, const char *file)
                else
                        page->html = markdown_to_string(page->text, 0, 0);
        } else {
-               page->html = g_strdup("Page not found");
+               page->error = g_strdup("403 Forbidden");
+               page->html  = g_strdup("Page not accessable\n");
        }
 }
 
 static void do_notfound(page_t *page, const char *path)
 {
-       page->html = "Page not found";
+       page->error = g_strdup("404 Not Found");
+       page->html  = g_strdup("Page not found\n");
 }
 
 static char *clean(const char *src)
@@ -277,9 +279,7 @@ static char *clean(const char *src)
 /* Main */
 int main(int argc, char **argv)
 {
-       char *path = clean(getenv("PATH_INFO") ?: "/aweather/");
-
-       print_header();
+       char *path = clean(getenv("PATH_INFO") ?: "/");
 
        page_t *page = get_page(path);
        menu_t *menu = get_menu(path);
@@ -303,6 +303,7 @@ int main(int argc, char **argv)
        g_free(index);
        g_free(file);
 
+       print_header(page);
        print_page(page, menu);
 
        return 0;
index a882093ef25244c20dd0aa6d5eb60d3e81431166..8493cd617e3214c511b540117c0ecbb91976d427 100644 (file)
@@ -1,7 +1,7 @@
-<% #include "string.h" %>
 <% #include "html.h" %>
 
-<% void print_header(void) { %>
+<% void print_header(page_t *page) { %>
+<% if (page->error) %><%% "Status: %s\n", page->error %>
 Content-Type: text/html;charset=UTF-8
 
 <% } %>
@@ -16,7 +16,7 @@ Content-Type: text/html;charset=UTF-8
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
-               <title><% if (page->title) printf("%s - ", page->title); %>pileus.org</title>
+               <title><% if (page->title) %><%% "%s - ", page->title %>pileus.org</title>
                <link href="<% href("theme/style.css"); %>" rel="stylesheet" type="text/css" />
                <meta http-equiv="X-UA-Compatible" content="IE=9" />
                <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
@@ -30,7 +30,7 @@ Content-Type: text/html;charset=UTF-8
        <body>
                <div class="title">
                        <a href="<% href(""); %>">pileus.org</a>
-                       <span><% if (page->title) printf("%s", page->title); %></span>
+                       <span><% if (page->title) %><%= page->title %></span>
                </div>
                <h1 class="nav">
                        <% print_menu(menu, 0, 0); %>
@@ -46,7 +46,12 @@ Content-Type: text/html;charset=UTF-8
                        <% print_menu(menu, 1, -1); %>
                </h2>
                <div class="content">
-                       <%= page->html %>
+                       <% if (page->error) { %>
+                               <h1><%= page->error %></h1>
+                               <h2><%= page->html  %></h2>
+                       <% } else { %>
+                               <%= page->html %>
+                       <% } %>
                        <div class="bottom"></div>
                </div>
                <div class="footer">