-rw-r--r-- | ui-shared.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/ui-shared.c b/ui-shared.c index 64ee79c..71c899a 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -43,220 +43,232 @@ void cgit_print_error(char *msg) | |||
43 | char *cgit_rooturl() | 43 | char *cgit_rooturl() |
44 | { | 44 | { |
45 | if (cgit_virtual_root) | 45 | if (cgit_virtual_root) |
46 | return fmt("%s/", cgit_virtual_root); | 46 | return fmt("%s/", cgit_virtual_root); |
47 | else | 47 | else |
48 | return cgit_script_name; | 48 | return cgit_script_name; |
49 | } | 49 | } |
50 | 50 | ||
51 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
52 | { | 52 | { |
53 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
54 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
55 | } else { | 55 | } else { |
56 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | char *cgit_pageurl(const char *reponame, const char *pagename, | 60 | char *cgit_pageurl(const char *reponame, const char *pagename, |
61 | const char *query) | 61 | const char *query) |
62 | { | 62 | { |
63 | if (cgit_virtual_root) { | 63 | if (cgit_virtual_root) { |
64 | if (query) | 64 | if (query) |
65 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, | 65 | return fmt("%s/%s/%s/?%s", cgit_virtual_root, reponame, |
66 | pagename, query); | 66 | pagename, query); |
67 | else | 67 | else |
68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, | 68 | return fmt("%s/%s/%s/", cgit_virtual_root, reponame, |
69 | pagename); | 69 | pagename); |
70 | } else { | 70 | } else { |
71 | if (query) | 71 | if (query) |
72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); | 72 | return fmt("?r=%s&p=%s&%s", reponame, pagename, query); |
73 | else | 73 | else |
74 | return fmt("?r=%s&p=%s", reponame, pagename); | 74 | return fmt("?r=%s&p=%s", reponame, pagename); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | char *cgit_currurl() | 78 | 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 | static char *repolink(char *title, char *class, char *page, char *head, | 90 | static char *repolink(char *title, char *class, char *page, char *head, |
91 | char *path) | 91 | char *path) |
92 | { | 92 | { |
93 | char *delim = "?"; | 93 | char *delim = "?"; |
94 | 94 | ||
95 | html("<a"); | 95 | html("<a"); |
96 | if (title) { | 96 | if (title) { |
97 | html(" title='"); | 97 | html(" title='"); |
98 | html_attr(title); | 98 | html_attr(title); |
99 | html("'"); | 99 | html("'"); |
100 | } | 100 | } |
101 | if (class) { | 101 | if (class) { |
102 | html(" class='"); | 102 | html(" class='"); |
103 | html_attr(class); | 103 | html_attr(class); |
104 | html("'"); | 104 | html("'"); |
105 | } | 105 | } |
106 | html(" href='"); | 106 | html(" href='"); |
107 | if (cgit_virtual_root) { | 107 | if (cgit_virtual_root) { |
108 | html_attr(cgit_virtual_root); | 108 | html_attr(cgit_virtual_root); |
109 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') | 109 | if (cgit_virtual_root[strlen(cgit_virtual_root) - 1] != '/') |
110 | html("/"); | 110 | html("/"); |
111 | html_attr(cgit_repo->url); | 111 | html_attr(cgit_repo->url); |
112 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 112 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
113 | html("/"); | 113 | html("/"); |
114 | html(page); | 114 | html(page); |
115 | html("/"); | 115 | html("/"); |
116 | if (path) | 116 | if (path) |
117 | html_attr(path); | 117 | html_attr(path); |
118 | } else { | 118 | } else { |
119 | html(cgit_script_name); | 119 | html(cgit_script_name); |
120 | html("?url="); | 120 | html("?url="); |
121 | html_attr(cgit_repo->url); | 121 | html_attr(cgit_repo->url); |
122 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') | 122 | if (cgit_repo->url[strlen(cgit_repo->url) - 1] != '/') |
123 | html("/"); | 123 | html("/"); |
124 | html(page); | 124 | html(page); |
125 | html("/"); | 125 | html("/"); |
126 | if (path) | 126 | if (path) |
127 | html_attr(path); | 127 | html_attr(path); |
128 | delim = "&"; | 128 | delim = "&"; |
129 | } | 129 | } |
130 | if (head && strcmp(head, cgit_repo->defbranch)) { | 130 | if (head && strcmp(head, cgit_repo->defbranch)) { |
131 | html(delim); | 131 | html(delim); |
132 | html("h="); | 132 | html("h="); |
133 | html_attr(head); | 133 | html_attr(head); |
134 | delim = "&"; | 134 | delim = "&"; |
135 | } | 135 | } |
136 | return fmt("%s", delim); | 136 | return fmt("%s", delim); |
137 | } | 137 | } |
138 | 138 | ||
139 | static char *reporevlink(char *page, char *name, char *title, char *class, | 139 | static void reporevlink(char *page, char *name, char *title, char *class, |
140 | char *head, char *rev, char *path) | 140 | char *head, char *rev, char *path) |
141 | { | 141 | { |
142 | char *delim; | 142 | char *delim; |
143 | 143 | ||
144 | delim = repolink(title, class, page, head, path); | 144 | delim = repolink(title, class, page, head, path); |
145 | if (rev && strcmp(rev, cgit_query_head)) { | 145 | if (rev && strcmp(rev, cgit_query_head)) { |
146 | html(delim); | 146 | html(delim); |
147 | html("id="); | 147 | html("id="); |
148 | html_attr(rev); | 148 | html_attr(rev); |
149 | } | 149 | } |
150 | html("'>"); | 150 | html("'>"); |
151 | html_txt(name); | 151 | html_txt(name); |
152 | html("</a>"); | 152 | html("</a>"); |
153 | } | 153 | } |
154 | 154 | ||
155 | void cgit_tree_link(char *name, char *title, char *class, char *head, | 155 | void cgit_tree_link(char *name, char *title, char *class, char *head, |
156 | char *rev, char *path) | 156 | char *rev, char *path) |
157 | { | 157 | { |
158 | reporevlink("tree", name, title, class, head, rev, path); | 158 | reporevlink("tree", name, title, class, head, rev, path); |
159 | } | 159 | } |
160 | 160 | ||
161 | void cgit_log_link(char *name, char *title, char *class, char *head, | 161 | void cgit_log_link(char *name, char *title, char *class, char *head, |
162 | char *rev, char *path) | 162 | char *rev, char *path) |
163 | { | 163 | { |
164 | reporevlink("log", name, title, class, head, rev, path); | 164 | reporevlink("log", name, title, class, head, rev, path); |
165 | } | 165 | } |
166 | 166 | ||
167 | void cgit_commit_link(char *name, char *title, char *class, char *head, | ||
168 | char *rev) | ||
169 | { | ||
170 | if (strlen(name) > cgit_max_msg_len && cgit_max_msg_len >= 15) { | ||
171 | name[cgit_max_msg_len] = '\0'; | ||
172 | name[cgit_max_msg_len - 1] = '.'; | ||
173 | name[cgit_max_msg_len - 2] = '.'; | ||
174 | name[cgit_max_msg_len - 3] = '.'; | ||
175 | } | ||
176 | reporevlink("commit", name, title, class, head, rev, NULL); | ||
177 | } | ||
178 | |||
167 | void cgit_print_date(time_t secs, char *format) | 179 | void cgit_print_date(time_t secs, char *format) |
168 | { | 180 | { |
169 | char buf[64]; | 181 | char buf[64]; |
170 | struct tm *time; | 182 | struct tm *time; |
171 | 183 | ||
172 | time = gmtime(&secs); | 184 | time = gmtime(&secs); |
173 | strftime(buf, sizeof(buf)-1, format, time); | 185 | strftime(buf, sizeof(buf)-1, format, time); |
174 | html_txt(buf); | 186 | html_txt(buf); |
175 | } | 187 | } |
176 | 188 | ||
177 | void cgit_print_age(time_t t, time_t max_relative, char *format) | 189 | void cgit_print_age(time_t t, time_t max_relative, char *format) |
178 | { | 190 | { |
179 | time_t now, secs; | 191 | time_t now, secs; |
180 | 192 | ||
181 | time(&now); | 193 | time(&now); |
182 | secs = now - t; | 194 | secs = now - t; |
183 | 195 | ||
184 | if (secs > max_relative && max_relative >= 0) { | 196 | if (secs > max_relative && max_relative >= 0) { |
185 | cgit_print_date(t, format); | 197 | cgit_print_date(t, format); |
186 | return; | 198 | return; |
187 | } | 199 | } |
188 | 200 | ||
189 | if (secs < TM_HOUR * 2) { | 201 | if (secs < TM_HOUR * 2) { |
190 | htmlf("<span class='age-mins'>%.0f min.</span>", | 202 | htmlf("<span class='age-mins'>%.0f min.</span>", |
191 | secs * 1.0 / TM_MIN); | 203 | secs * 1.0 / TM_MIN); |
192 | return; | 204 | return; |
193 | } | 205 | } |
194 | if (secs < TM_DAY * 2) { | 206 | if (secs < TM_DAY * 2) { |
195 | htmlf("<span class='age-hours'>%.0f hours</span>", | 207 | htmlf("<span class='age-hours'>%.0f hours</span>", |
196 | secs * 1.0 / TM_HOUR); | 208 | secs * 1.0 / TM_HOUR); |
197 | return; | 209 | return; |
198 | } | 210 | } |
199 | if (secs < TM_WEEK * 2) { | 211 | if (secs < TM_WEEK * 2) { |
200 | htmlf("<span class='age-days'>%.0f days</span>", | 212 | htmlf("<span class='age-days'>%.0f days</span>", |
201 | secs * 1.0 / TM_DAY); | 213 | secs * 1.0 / TM_DAY); |
202 | return; | 214 | return; |
203 | } | 215 | } |
204 | if (secs < TM_MONTH * 2) { | 216 | if (secs < TM_MONTH * 2) { |
205 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 217 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
206 | secs * 1.0 / TM_WEEK); | 218 | secs * 1.0 / TM_WEEK); |
207 | return; | 219 | return; |
208 | } | 220 | } |
209 | if (secs < TM_YEAR * 2) { | 221 | if (secs < TM_YEAR * 2) { |
210 | htmlf("<span class='age-months'>%.0f months</span>", | 222 | htmlf("<span class='age-months'>%.0f months</span>", |
211 | secs * 1.0 / TM_MONTH); | 223 | secs * 1.0 / TM_MONTH); |
212 | return; | 224 | return; |
213 | } | 225 | } |
214 | htmlf("<span class='age-years'>%.0f years</span>", | 226 | htmlf("<span class='age-years'>%.0f years</span>", |
215 | secs * 1.0 / TM_YEAR); | 227 | secs * 1.0 / TM_YEAR); |
216 | } | 228 | } |
217 | 229 | ||
218 | void cgit_print_docstart(char *title, struct cacheitem *item) | 230 | void cgit_print_docstart(char *title, struct cacheitem *item) |
219 | { | 231 | { |
220 | html("Content-Type: text/html; charset=utf-8\n"); | 232 | html("Content-Type: text/html; charset=utf-8\n"); |
221 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 233 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
222 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 234 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
223 | ttl_seconds(item->ttl))); | 235 | ttl_seconds(item->ttl))); |
224 | html("\n"); | 236 | html("\n"); |
225 | html(cgit_doctype); | 237 | html(cgit_doctype); |
226 | html("<html>\n"); | 238 | html("<html>\n"); |
227 | html("<head>\n"); | 239 | html("<head>\n"); |
228 | html("<title>"); | 240 | html("<title>"); |
229 | html_txt(title); | 241 | html_txt(title); |
230 | html("</title>\n"); | 242 | html("</title>\n"); |
231 | htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version); | 243 | htmlf("<meta name='generator' content='cgit v%s'/>\n", cgit_version); |
232 | html("<link rel='stylesheet' type='text/css' href='"); | 244 | html("<link rel='stylesheet' type='text/css' href='"); |
233 | html_attr(cgit_css); | 245 | html_attr(cgit_css); |
234 | html("'/>\n"); | 246 | html("'/>\n"); |
235 | html("</head>\n"); | 247 | html("</head>\n"); |
236 | html("<body>\n"); | 248 | html("<body>\n"); |
237 | } | 249 | } |
238 | 250 | ||
239 | void cgit_print_docend() | 251 | void cgit_print_docend() |
240 | { | 252 | { |
241 | html("</td></tr></table>"); | 253 | html("</td></tr></table>"); |
242 | html("</body>\n</html>\n"); | 254 | html("</body>\n</html>\n"); |
243 | } | 255 | } |
244 | 256 | ||
245 | void cgit_print_pageheader(char *title, int show_search) | 257 | void cgit_print_pageheader(char *title, int show_search) |
246 | { | 258 | { |
247 | html("<table id='layout'>"); | 259 | html("<table id='layout'>"); |
248 | html("<tr><td id='header'>"); | 260 | html("<tr><td id='header'>"); |
249 | html(cgit_root_title); | 261 | html(cgit_root_title); |
250 | html("</td><td id='logo'>"); | 262 | html("</td><td id='logo'>"); |
251 | html("<a href='"); | 263 | html("<a href='"); |
252 | html_attr(cgit_logo_link); | 264 | html_attr(cgit_logo_link); |
253 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); | 265 | htmlf("'><img src='%s' alt='logo'/></a>", cgit_logo); |
254 | html("</td></tr>"); | 266 | html("</td></tr>"); |
255 | html("<tr><td id='crumb'>"); | 267 | html("<tr><td id='crumb'>"); |
256 | htmlf("<a href='%s'>root</a>", cgit_rooturl()); | 268 | htmlf("<a href='%s'>root</a>", cgit_rooturl()); |
257 | if (cgit_query_repo) { | 269 | if (cgit_query_repo) { |
258 | htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url)); | 270 | htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url)); |
259 | html_txt(cgit_repo->name); | 271 | html_txt(cgit_repo->name); |
260 | htmlf("</a> : %s", title); | 272 | htmlf("</a> : %s", title); |
261 | } | 273 | } |
262 | html("</td>"); | 274 | html("</td>"); |