get PPA template from file
[ppastats.git] / src / html.c
index 07945f6..f4e2790 100644 (file)
@@ -37,6 +37,7 @@
 #include "ppastats.h"
 
 static char *footer;
+static char *ppa_body;
 
 #define HTML_PKG_TEMPLATE \
 "      <h1><span id=\"pkg_name\">N/A</span></h1>\n\
@@ -124,18 +125,6 @@ src=\"js/excanvas.js\"></script><![endif]-->\n\
        </head>\n\
        <body>\n"
 
-#define HTML_INDEX_TEMPLATE \
-"      <h1><span id=\"ppa_name\">N/A</span></h1>\n\
-       <div id=\"details\">\n\
-               <div class=\"pkgs\">\n\
-                       <em>Packages</em>:\n\
-                       <ul id=\"pkgs\"></ul>\n\
-               </div>\n\
-       </div>\n\
-       <div  id=\"charts\">\n\
-               <div id=\"chart\"></div>\n\
-       </div>\n"
-
 static char *path_new(const char *dir, const char *file, const char *suffixe)
 {
        char *path;
@@ -154,8 +143,6 @@ static char *path_new(const char *dir, const char *file, const char *suffixe)
        return path;
 }
 
-
-
 static const char *get_footer()
 {
        const char *path;
@@ -171,6 +158,22 @@ static const char *get_footer()
        return footer;
 }
 
+static const char *get_ppa_body()
+{
+       const char *path;
+
+       if (!ppa_body) {
+               path = DEFAULT_WWW_DIR"/ppa.tpl";
+               ppa_body = file_get_content(path);
+
+               if (!ppa_body)
+                       log_err("Failed to read PPA template: %s", path);
+       }
+
+       return ppa_body;
+}
+
+
 static struct json_object *date_to_json(struct tm *tm)
 {
        json_object *json;
@@ -463,6 +466,13 @@ index_to_html(struct ppa_stats *ppa, const char *dir)
 {
        char *path, *json_path, *dname;
        json_object *json;
+       const char *body;
+
+       body = get_ppa_body();
+       if (!body) {
+               log_err("Failed to create PPA page");
+               return ;
+       }
 
        json = ppa_to_json(ppa);
        json_path = path_new(dir, "index", ".json");
@@ -474,7 +484,7 @@ index_to_html(struct ppa_stats *ppa, const char *dir)
 
        path = path_new(dir, "index", ".html");
        dname = ppa_display_name(ppa);
-       create_html(path, dname, HTML_INDEX_TEMPLATE, "ppastats_ppa();");
+       create_html(path, dname, body, "ppastats_ppa();");
        free(path);
        free(dname);
 }