added string replace fct
[ppastats.git] / src / html.c
index f4e2790..b2e9e34 100644 (file)
 
 static char *footer;
 static char *ppa_body;
-
-#define HTML_PKG_TEMPLATE \
-"      <h1><span id=\"pkg_name\">N/A</span></h1>\n\
-       <div id=\"charts\">\n\
-               <div id=\"chart\"></div>\n\
-               <div id=\"chart_distro\"></div>\n\
-       </div>\n\
-       <div id=\"details\">\n\
-               <em>PPA</em>: \n\
-               <a href=\"index.html\">\n\
-               <span id=\"ppa_owner\">N/A</span>/\n\
-               <span id=\"ppa_name\">N/A</span>\n\
-               </a>\n\
-\n\
-               <div id=\"distros\"><em>Distros:</em></div>\n\
-               <div id=\"versions\"><em>Versions:</em></div>\n\
-       </div>"
+static char *pkg_body;
 
 #define HTML_VERSION_TEMPLATE \
 "<html>\n\
@@ -173,6 +157,20 @@ static const char *get_ppa_body()
        return ppa_body;
 }
 
+static const char *get_pkg_body()
+{
+       const char *path;
+
+       if (!pkg_body) {
+               path = DEFAULT_WWW_DIR"/pkg.tpl";
+               pkg_body = file_get_content(path);
+
+               if (!pkg_body)
+                       log_err("Failed to read package template: %s", path);
+       }
+
+       return pkg_body;
+}
 
 static struct json_object *date_to_json(struct tm *tm)
 {
@@ -494,6 +492,13 @@ pkg_to_html(struct ppa_stats *ppa, struct package_stats *pkg, const char *dir)
 {
        char *path, *json_path, *script;
        json_object *json;
+       const char *body;
+
+       body = get_pkg_body();
+       if (!body) {
+               log_err("Failed to create package page: %s", pkg->name);
+               return ;
+       }
 
        json_path = path_new(dir, pkg->name, ".json");
        json = pkg_to_json(ppa, pkg);
@@ -512,7 +517,7 @@ pkg_to_html(struct ppa_stats *ppa, struct package_stats *pkg, const char *dir)
 
        log_debug(_("generating %s"), path);
 
-       create_html(path, pkg->name, HTML_PKG_TEMPLATE, script);
+       create_html(path, pkg->name, body, script);
        free(path);
        free(script);
 }