summaryrefslogtreecommitdiffabout
path: root/ui-shared.c
Unidiff
Diffstat (limited to 'ui-shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-shared.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/ui-shared.c b/ui-shared.c
index c7fbc5e..acc771b 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -79,34 +79,75 @@ char *cgit_currurl()
79{ 79{
80 if (!cgit_virtual_root) 80 if (!cgit_virtual_root)
81 return cgit_script_name; 81 return cgit_script_name;
82 else if (cgit_query_page) 82 else if (cgit_query_page)
83 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page); 83 return fmt("%s/%s/%s/", cgit_virtual_root, cgit_query_repo, cgit_query_page);
84 else if (cgit_query_repo) 84 else if (cgit_query_repo)
85 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo); 85 return fmt("%s/%s/", cgit_virtual_root, cgit_query_repo);
86 else 86 else
87 return fmt("%s/", cgit_virtual_root); 87 return fmt("%s/", cgit_virtual_root);
88} 88}
89 89
90 90
91void cgit_print_date(unsigned long secs) 91void cgit_print_date(time_t secs, char *format)
92{ 92{
93 char buf[32]; 93 char buf[64];
94 struct tm *time; 94 struct tm *time;
95 95
96 time = gmtime(&secs); 96 time = gmtime(&secs);
97 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", time); 97 strftime(buf, sizeof(buf)-1, format, time);
98 html_txt(buf); 98 html_txt(buf);
99} 99}
100 100
101void cgit_print_age(time_t t, time_t max_relative, char *format)
102{
103 time_t now, secs;
104
105 time(&now);
106 secs = now - t;
107
108 if (secs > max_relative && max_relative >= 0) {
109 cgit_print_date(t, format);
110 return;
111 }
112
113 if (secs < TM_HOUR * 2) {
114 htmlf("<span class='age-mins'>%.0f min.</span>",
115 secs * 1.0 / TM_MIN);
116 return;
117 }
118 if (secs < TM_DAY * 2) {
119 htmlf("<span class='age-hours'>%.0f hours</span>",
120 secs * 1.0 / TM_HOUR);
121 return;
122 }
123 if (secs < TM_WEEK * 2) {
124 htmlf("<span class='age-days'>%.0f days</span>",
125 secs * 1.0 / TM_DAY);
126 return;
127 }
128 if (secs < TM_MONTH * 2) {
129 htmlf("<span class='age-weeks'>%.0f weeks</span>",
130 secs * 1.0 / TM_WEEK);
131 return;
132 }
133 if (secs < TM_YEAR * 2) {
134 htmlf("<span class='age-months'>%.0f months</span>",
135 secs * 1.0 / TM_MONTH);
136 return;
137 }
138 htmlf("<span class='age-years'>%.0f years</span>",
139 secs * 1.0 / TM_YEAR);
140}
141
101void cgit_print_docstart(char *title, struct cacheitem *item) 142void cgit_print_docstart(char *title, struct cacheitem *item)
102{ 143{
103 html("Content-Type: text/html; charset=utf-8\n"); 144 html("Content-Type: text/html; charset=utf-8\n");
104 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); 145 htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime));
105 htmlf("Expires: %s\n", http_date(item->st.st_mtime + 146 htmlf("Expires: %s\n", http_date(item->st.st_mtime +
106 ttl_seconds(item->ttl))); 147 ttl_seconds(item->ttl)));
107 html("\n"); 148 html("\n");
108 html(cgit_doctype); 149 html(cgit_doctype);
109 html("<html>\n"); 150 html("<html>\n");
110 html("<head>\n"); 151 html("<head>\n");
111 html("<title>"); 152 html("<title>");
112 html_txt(title); 153 html_txt(title);