Replace the --base code with relative paths.
[darkstat] / html.c
diff --git a/html.c b/html.c
index 6e98aaa..0bdd384 100644 (file)
--- a/html.c
+++ b/html.c
 #include "config.h"
 #include "str.h"
 #include "html.h"
-#include "http.h" /* for http_base_url */
 #include "opt.h"
 
-void html_open(struct str *buf, const char *title,
+#include <assert.h>
+
+static const char *relpaths[] = {
+    ".",
+    "..",
+    "../.."
+};
+
+void html_open(struct str *buf, const char *title, const int path_depth,
     const int want_graph_js)
 {
+    assert(path_depth < (sizeof(relpaths)/sizeof(char *)));
+    const char *root = relpaths[path_depth];
+
     str_appendf(buf,
         "<!DOCTYPE html>\n"
         "<html>\n"
@@ -25,13 +35,13 @@ void html_open(struct str *buf, const char *title,
          "<title>%s (darkstat3 %s)</title>\n"
          "<meta name=\"generator\" content=\"" PACKAGE_STRING "\">\n"
          "<meta name=\"robots\" content=\"noindex, noarchive\">\n"
-         "<link rel=\"stylesheet\" href=\"%sstyle.css\" type=\"text/css\">\n"
-        , title, opt_interface, http_base_url);
+         "<link rel=\"stylesheet\" href=\"%s/style.css\" type=\"text/css\">\n"
+        , title, opt_interface, root);
 
     if (want_graph_js)
         str_appendf(buf,
-            "<script src=\"%sgraph.js\" type=\"text/javascript\"></script>\n"
-            , http_base_url);
+            "<script src=\"%s/graph.js\" type=\"text/javascript\"></script>\n"
+            , root);
 
     str_appendf(buf,
         "</head>\n"
@@ -39,14 +49,14 @@ void html_open(struct str *buf, const char *title,
         "<div class=\"menu\">\n"
         "<ul class=\"menu\">" /* no whitespace (newlines) in list */
          "<li class=\"label\">" PACKAGE_STRING "</li>"
-         "<li><a href=\"%s\">graphs</a></li>"
-         "<li><a href=\"%shosts/\">hosts</a></li>"
+         "<li><a href=\"%s/\">graphs</a></li>"
+         "<li><a href=\"%s/hosts/\">hosts</a></li>"
          "<li><a href=\"" PACKAGE_URL "\">homepage</a></li>"
         "</ul>\n"
         "</div>\n"
         "<div class=\"content\">\n"
          "<h2 class=\"pageheader\">%s</h2>\n"
-        , http_base_url, http_base_url, title);
+        , root, root, title);
 }
 
 void html_close(struct str *buf)