fix: inject <base href> from base_path config; fix relative asset/nav links; add README
This commit is contained in:
+2
-2
@@ -117,7 +117,7 @@ void handle_series_show(int fd, const char *qs) {
|
||||
buf_free(&inl);
|
||||
|
||||
free(sid); free(title_raw); free(cover_raw); free(json);
|
||||
send_page(fd, "Series", &b, "/series_show.js");
|
||||
send_page(fd, "Series", &b, "series_show.js");
|
||||
buf_free(&b);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ void handle_downloads(int fd) {
|
||||
"<button class='btn btn-r' onclick=cleanPartials()>clean partial files</button>"
|
||||
"</div>"
|
||||
"<div id=dl-table><p style='color:var(--dim)'>loading...</p></div>");
|
||||
send_page(fd, "Downloads", &b, "/downloads.js");
|
||||
send_page(fd, "Downloads", &b, "downloads.js");
|
||||
buf_free(&b);
|
||||
}
|
||||
|
||||
|
||||
+12
-1
@@ -77,8 +77,19 @@ int parse_request(int fd, Req *req) {
|
||||
void send_page(int fd, const char *title, Buf *body, const char *script_src) {
|
||||
Buf page; buf_init(&page);
|
||||
buf_str(&page, "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nConnection: close\r\n\r\n");
|
||||
/* inject <base href> so relative assets resolve correctly at any sub-path */
|
||||
const char *ph = strstr(g_header, "{{TITLE}}");
|
||||
if (ph) {
|
||||
const char *head_end = strstr(g_header, "</head>");
|
||||
if (ph && head_end && head_end > ph) {
|
||||
/* write up to </head>, inject base tag, then rest of header */
|
||||
buf_append(&page, g_header, ph - g_header);
|
||||
buf_str(&page, title);
|
||||
const char *after_title = ph + 9;
|
||||
buf_append(&page, after_title, head_end - after_title);
|
||||
if (g_cfg.base_path[0])
|
||||
buf_fmt(&page, "<base href=\"%s/\">", g_cfg.base_path);
|
||||
buf_str(&page, head_end);
|
||||
} else if (ph) {
|
||||
buf_append(&page, g_header, ph - g_header);
|
||||
buf_str(&page, title);
|
||||
buf_str(&page, ph + 9);
|
||||
|
||||
Reference in New Issue
Block a user