]> git.cameronkatri.com Git - cgit.git/blobdiff - ui-shared.c
ui-shared: HTML-ize DOCTYPE and <html>
[cgit.git] / ui-shared.c
index eaa45fb402f21aefcff21afe53e2bacae1ec0534..1529ff1c15c191eda2a3225579cc0cd6175ffc17 100644 (file)
@@ -12,8 +12,7 @@
 #include "html.h"
 
 static const char cgit_doctype[] =
-"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
-"  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
+"<!DOCTYPE html>\n";
 
 static char *http_date(time_t t)
 {
@@ -607,31 +606,10 @@ void cgit_submodule_link(const char *class, char *path, const char *rev)
                path[len - 1] = tail;
 }
 
-static const char *fmt_date(time_t secs, const char *format, int local_time)
-{
-       static char buf[64];
-       struct tm *time;
-
-       if (!secs)
-               return "";
-       if (local_time)
-               time = localtime(&secs);
-       else
-               time = gmtime(&secs);
-       strftime(buf, sizeof(buf)-1, format, time);
-       return buf;
-}
-
-void cgit_print_date(time_t secs, const char *format, int local_time)
-{
-       html_txt(fmt_date(secs, format, local_time));
-}
-
-const struct date_mode *cgit_date_mode(const char *format)
+const struct date_mode *cgit_date_mode(enum date_mode_type type)
 {
        static struct date_mode mode;
-       mode.type = DATE_STRFTIME;
-       mode.strftime_fmt = format;
+       mode.type = type;
        mode.local = ctx.cfg.local_time;
        return &mode;
 }
@@ -640,7 +618,7 @@ static void print_rel_date(time_t t, int tz, double value,
        const char *class, const char *suffix)
 {
        htmlf("<span class='%s' title='", class);
-       html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE)));
+       html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
        htmlf("'>%.0f %s</span>", value, suffix);
 }
 
@@ -657,9 +635,9 @@ void cgit_print_age(time_t t, int tz, time_t max_relative)
 
        if (secs > max_relative && max_relative >= 0) {
                html("<span title='");
-               html_attr(show_date(t, tz, cgit_date_mode(FMT_LONGDATE)));
+               html_attr(show_date(t, tz, cgit_date_mode(DATE_ISO8601)));
                html("'>");
-               html_txt(show_date(t, tz, cgit_date_mode(FMT_SHORTDATE)));
+               html_txt(show_date(t, tz, cgit_date_mode(DATE_SHORT)));
                html("</span>");
                return;
        }
@@ -723,7 +701,6 @@ void cgit_redirect(const char *url, bool permanent)
        html("Location: ");
        html_url_path(url);
        html("\n\n");
-       exit(0);
 }
 
 static void print_rel_vcs_link(const char *url)
@@ -745,7 +722,7 @@ void cgit_print_docstart(void)
 
        char *host = cgit_hosturl();
        html(cgit_doctype);
-       html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n");
+       html("<html lang='en'>\n");
        html("<head>\n");
        html("<title>");
        html_txt(ctx.page.title);
@@ -801,7 +778,7 @@ void cgit_print_docend(void)
        else {
                htmlf("<div class='footer'>generated by <a href='http://git.zx2c4.com/cgit/about/'>cgit %s</a> at ",
                        cgit_version);
-               html_txt(show_date(time(NULL), 0, cgit_date_mode(FMT_LONGDATE)));
+               html_txt(show_date(time(NULL), 0, cgit_date_mode(DATE_ISO8601)));
                html("</div>\n");
        }
        html("</div> <!-- id=cgit -->\n");
@@ -814,13 +791,11 @@ void cgit_print_error_page(int code, const char *msg, const char *fmt, ...)
        ctx.page.expires = ctx.cfg.cache_dynamic_ttl;
        ctx.page.status = code;
        ctx.page.statusmsg = msg;
-       cgit_print_http_headers();
-       cgit_print_docstart();
-       cgit_print_pageheader();
+       cgit_print_layout_start();
        va_start(ap, fmt);
        cgit_vprint_error(fmt, ap);
        va_end(ap);
-       cgit_print_docend();
+       cgit_print_layout_end();
 }
 
 void cgit_print_layout_start(void)
@@ -1018,6 +993,11 @@ void cgit_print_pageheader(void)
                if (ctx.repo->max_stats)
                        cgit_stats_link("stats", NULL, hc("stats"),
                                        ctx.qry.head, ctx.qry.vpath);
+               if (ctx.repo->homepage) {
+                       html("<a href='");
+                       html_attr(ctx.repo->homepage);
+                       html("'>homepage</a>");
+               }
                html("</td><td class='form'>");
                html("<form class='right' method='get' action='");
                if (ctx.cfg.virtual_root) {