-rw-r--r-- | ui-shared.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/ui-shared.c b/ui-shared.c index 172499c..bca50aa 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -31,24 +31,32 @@ static long ttl_seconds(long ttl) | |||
31 | return 60 * 60 * 24 * 365; | 31 | return 60 * 60 * 24 * 365; |
32 | else | 32 | else |
33 | return ttl * 60; | 33 | return ttl * 60; |
34 | } | 34 | } |
35 | 35 | ||
36 | void cgit_print_error(char *msg) | 36 | void cgit_print_error(char *msg) |
37 | { | 37 | { |
38 | html("<div class='error'>"); | 38 | html("<div class='error'>"); |
39 | html_txt(msg); | 39 | html_txt(msg); |
40 | html("</div>\n"); | 40 | html("</div>\n"); |
41 | } | 41 | } |
42 | 42 | ||
43 | char *cgit_rooturl() | ||
44 | { | ||
45 | if (cgit_virtual_root) | ||
46 | return fmt("%s/", cgit_virtual_root); | ||
47 | else | ||
48 | return "./cgit.cgi"; | ||
49 | } | ||
50 | |||
43 | char *cgit_repourl(const char *reponame) | 51 | char *cgit_repourl(const char *reponame) |
44 | { | 52 | { |
45 | if (cgit_virtual_root) { | 53 | if (cgit_virtual_root) { |
46 | return fmt("%s/%s/", cgit_virtual_root, reponame); | 54 | return fmt("%s/%s/", cgit_virtual_root, reponame); |
47 | } else { | 55 | } else { |
48 | return fmt("?r=%s", reponame); | 56 | return fmt("?r=%s", reponame); |
49 | } | 57 | } |
50 | } | 58 | } |
51 | 59 | ||
52 | char *cgit_pageurl(const char *reponame, const char *pagename, | 60 | char *cgit_pageurl(const char *reponame, const char *pagename, |
53 | const char *query) | 61 | const char *query) |
54 | { | 62 | { |
@@ -104,54 +112,63 @@ void cgit_print_docstart(char *title, struct cacheitem *item) | |||
104 | html("</head>\n"); | 112 | html("</head>\n"); |
105 | html("<body>\n"); | 113 | html("<body>\n"); |
106 | } | 114 | } |
107 | 115 | ||
108 | void cgit_print_docend() | 116 | void cgit_print_docend() |
109 | { | 117 | { |
110 | html("</td></tr></table>"); | 118 | html("</td></tr></table>"); |
111 | html("</body>\n</html>\n"); | 119 | html("</body>\n</html>\n"); |
112 | } | 120 | } |
113 | 121 | ||
114 | void cgit_print_pageheader(char *title, int show_search) | 122 | void cgit_print_pageheader(char *title, int show_search) |
115 | { | 123 | { |
116 | html("<table id='layout'><tr><td id='header'>"); | 124 | html("<table id='layout'>"); |
117 | htmlf("<a href='%s'>", cgit_logo_link); | 125 | html("<tr><td id='header'>"); |
118 | htmlf("<img id='logo' src='%s'/>\n", cgit_logo); | 126 | html(cgit_root_title); |
119 | htmlf("</a>"); | 127 | html("</td><td id='logo'>"); |
128 | html("<a href='"); | ||
129 | html_attr(cgit_logo_link); | ||
130 | htmlf("'><img src='%s'/></a>", cgit_logo); | ||
131 | html("</td></tr>"); | ||
132 | html("<tr><td id='crumb'>"); | ||
133 | htmlf("<a href='%s'>root</a>", cgit_rooturl()); | ||
134 | if (cgit_query_repo) { | ||
135 | htmlf(" : <a href='%s'>", cgit_repourl(cgit_repo->url)); | ||
136 | html_txt(cgit_repo->name); | ||
137 | htmlf("</a> : %s", title); | ||
138 | } | ||
139 | html("</td>"); | ||
140 | html("<td id='search'>"); | ||
120 | if (show_search) { | 141 | if (show_search) { |
121 | html("<form method='get' href='"); | 142 | html("<form method='get' href='"); |
122 | html_attr(cgit_currurl()); | 143 | html_attr(cgit_currurl()); |
123 | html("'>"); | 144 | html("'>"); |
124 | if (!cgit_virtual_root) { | 145 | if (!cgit_virtual_root) { |
125 | if (cgit_query_repo) | 146 | if (cgit_query_repo) |
126 | html_hidden("r", cgit_query_repo); | 147 | html_hidden("r", cgit_query_repo); |
127 | if (cgit_query_page) | 148 | if (cgit_query_page) |
128 | html_hidden("p", cgit_query_page); | 149 | html_hidden("p", cgit_query_page); |
129 | } | 150 | } |
130 | if (cgit_query_head) | 151 | if (cgit_query_head) |
131 | html_hidden("h", cgit_query_head); | 152 | html_hidden("h", cgit_query_head); |
132 | if (cgit_query_sha1) | 153 | if (cgit_query_sha1) |
133 | html_hidden("id", cgit_query_sha1); | 154 | html_hidden("id", cgit_query_sha1); |
134 | if (cgit_query_sha2) | 155 | if (cgit_query_sha2) |
135 | html_hidden("id2", cgit_query_sha2); | 156 | html_hidden("id2", cgit_query_sha2); |
136 | html("<input type='text' name='q' value='"); | 157 | html("<input type='text' name='q' value='"); |
137 | html_attr(cgit_query_search); | 158 | html_attr(cgit_query_search); |
138 | html("'/></form>"); | 159 | html("'/></form>"); |
139 | } | 160 | } |
140 | if (cgit_query_repo) | 161 | html("</td></tr>"); |
141 | htmlf("<a href='%s'>", cgit_repourl(cgit_query_repo)); | 162 | html("<tr><td id='content' colspan='2'>"); |
142 | html_txt(title); | ||
143 | if (cgit_query_repo) | ||
144 | html("</a>"); | ||
145 | html("</td></tr><tr><td id='content'>"); | ||
146 | } | 163 | } |
147 | 164 | ||
148 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, | 165 | void cgit_print_snapshot_start(const char *mimetype, const char *filename, |
149 | struct cacheitem *item) | 166 | struct cacheitem *item) |
150 | { | 167 | { |
151 | htmlf("Content-Type: %s\n", mimetype); | 168 | htmlf("Content-Type: %s\n", mimetype); |
152 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); | 169 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", filename); |
153 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); | 170 | htmlf("Last-Modified: %s\n", http_date(item->st.st_mtime)); |
154 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + | 171 | htmlf("Expires: %s\n", http_date(item->st.st_mtime + |
155 | ttl_seconds(item->ttl))); | 172 | ttl_seconds(item->ttl))); |
156 | html("\n"); | 173 | html("\n"); |
157 | } | 174 | } |