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
};
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);
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)
/* 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);
g_free(index);
g_free(file);
+ print_header(page);
print_page(page, menu);
return 0;
-<% #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
<% } %>
"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" />
<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); %>
<% 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">