-rw-r--r-- | ui-shared.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/ui-shared.c b/ui-shared.c index 10be3c0..66d5b82 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -455,130 +455,132 @@ void cgit_print_age(time_t t, time_t max_relative, char *format) | |||
455 | htmlf("<span class='age-weeks'>%.0f weeks</span>", | 455 | htmlf("<span class='age-weeks'>%.0f weeks</span>", |
456 | secs * 1.0 / TM_WEEK); | 456 | secs * 1.0 / TM_WEEK); |
457 | return; | 457 | return; |
458 | } | 458 | } |
459 | if (secs < TM_YEAR * 2) { | 459 | if (secs < TM_YEAR * 2) { |
460 | htmlf("<span class='age-months'>%.0f months</span>", | 460 | htmlf("<span class='age-months'>%.0f months</span>", |
461 | secs * 1.0 / TM_MONTH); | 461 | secs * 1.0 / TM_MONTH); |
462 | return; | 462 | return; |
463 | } | 463 | } |
464 | htmlf("<span class='age-years'>%.0f years</span>", | 464 | htmlf("<span class='age-years'>%.0f years</span>", |
465 | secs * 1.0 / TM_YEAR); | 465 | secs * 1.0 / TM_YEAR); |
466 | } | 466 | } |
467 | 467 | ||
468 | void cgit_print_http_headers(struct cgit_context *ctx) | 468 | void cgit_print_http_headers(struct cgit_context *ctx) |
469 | { | 469 | { |
470 | const char *method = getenv("REQUEST_METHOD"); | 470 | const char *method = getenv("REQUEST_METHOD"); |
471 | 471 | ||
472 | if (ctx->page.status) | 472 | if (ctx->page.status) |
473 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); | 473 | htmlf("Status: %d %s\n", ctx->page.status, ctx->page.statusmsg); |
474 | if (ctx->page.mimetype && ctx->page.charset) | 474 | if (ctx->page.mimetype && ctx->page.charset) |
475 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, | 475 | htmlf("Content-Type: %s; charset=%s\n", ctx->page.mimetype, |
476 | ctx->page.charset); | 476 | ctx->page.charset); |
477 | else if (ctx->page.mimetype) | 477 | else if (ctx->page.mimetype) |
478 | htmlf("Content-Type: %s\n", ctx->page.mimetype); | 478 | htmlf("Content-Type: %s\n", ctx->page.mimetype); |
479 | if (ctx->page.size) | 479 | if (ctx->page.size) |
480 | htmlf("Content-Length: %ld\n", ctx->page.size); | 480 | htmlf("Content-Length: %ld\n", ctx->page.size); |
481 | if (ctx->page.filename) | 481 | if (ctx->page.filename) |
482 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 482 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
483 | ctx->page.filename); | 483 | ctx->page.filename); |
484 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 484 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
485 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 485 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
486 | if (ctx->page.etag) | 486 | if (ctx->page.etag) |
487 | htmlf("ETag: \"%s\"\n", ctx->page.etag); | 487 | htmlf("ETag: \"%s\"\n", ctx->page.etag); |
488 | html("\n"); | 488 | html("\n"); |
489 | if (method && !strcmp(method, "HEAD")) | 489 | if (method && !strcmp(method, "HEAD")) |
490 | exit(0); | 490 | exit(0); |
491 | } | 491 | } |
492 | 492 | ||
493 | void cgit_print_docstart(struct cgit_context *ctx) | 493 | void cgit_print_docstart(struct cgit_context *ctx) |
494 | { | 494 | { |
495 | char *host = cgit_hosturl(); | 495 | char *host = cgit_hosturl(); |
496 | html(cgit_doctype); | 496 | html(cgit_doctype); |
497 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 497 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
498 | html("<head>\n"); | 498 | html("<head>\n"); |
499 | html("<title>"); | 499 | html("<title>"); |
500 | html_txt(ctx->page.title); | 500 | html_txt(ctx->page.title); |
501 | html("</title>\n"); | 501 | html("</title>\n"); |
502 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 502 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
503 | if (ctx->cfg.robots && *ctx->cfg.robots) | 503 | if (ctx->cfg.robots && *ctx->cfg.robots) |
504 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 504 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
505 | html("<link rel='stylesheet' type='text/css' href='"); | 505 | html("<link rel='stylesheet' type='text/css' href='"); |
506 | html_attr(ctx->cfg.css); | 506 | html_attr(ctx->cfg.css); |
507 | html("'/>\n"); | 507 | html("'/>\n"); |
508 | if (ctx->cfg.favicon) { | 508 | if (ctx->cfg.favicon) { |
509 | html("<link rel='shortcut icon' href='"); | 509 | html("<link rel='shortcut icon' href='"); |
510 | html_attr(ctx->cfg.favicon); | 510 | html_attr(ctx->cfg.favicon); |
511 | html("'/>\n"); | 511 | html("'/>\n"); |
512 | } | 512 | } |
513 | if (host && ctx->repo) { | 513 | if (host && ctx->repo) { |
514 | html("<link rel='alternate' title='Atom feed' href='"); | 514 | html("<link rel='alternate' title='Atom feed' href='"); |
515 | html(cgit_httpscheme()); | 515 | html(cgit_httpscheme()); |
516 | html_attr(cgit_hosturl()); | 516 | html_attr(cgit_hosturl()); |
517 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 517 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, |
518 | fmt("h=%s", ctx->qry.head))); | 518 | fmt("h=%s", ctx->qry.head))); |
519 | html("' type='application/atom+xml'/>"); | 519 | html("' type='application/atom+xml'/>\n"); |
520 | } | 520 | } |
521 | if (ctx->cfg.head_include) | ||
522 | html_include(ctx->cfg.head_include); | ||
521 | html("</head>\n"); | 523 | html("</head>\n"); |
522 | html("<body>\n"); | 524 | html("<body>\n"); |
523 | if (ctx->cfg.header) | 525 | if (ctx->cfg.header) |
524 | html_include(ctx->cfg.header); | 526 | html_include(ctx->cfg.header); |
525 | } | 527 | } |
526 | 528 | ||
527 | void cgit_print_docend() | 529 | void cgit_print_docend() |
528 | { | 530 | { |
529 | html("</div>"); | 531 | html("</div>"); |
530 | if (ctx.cfg.footer) | 532 | if (ctx.cfg.footer) |
531 | html_include(ctx.cfg.footer); | 533 | html_include(ctx.cfg.footer); |
532 | else { | 534 | else { |
533 | htmlf("<div class='footer'>generated by cgit %s at ", | 535 | htmlf("<div class='footer'>generated by cgit %s at ", |
534 | cgit_version); | 536 | cgit_version); |
535 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 537 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
536 | html("</div>\n"); | 538 | html("</div>\n"); |
537 | } | 539 | } |
538 | html("</body>\n</html>\n"); | 540 | html("</body>\n</html>\n"); |
539 | } | 541 | } |
540 | 542 | ||
541 | int print_branch_option(const char *refname, const unsigned char *sha1, | 543 | int print_branch_option(const char *refname, const unsigned char *sha1, |
542 | int flags, void *cb_data) | 544 | int flags, void *cb_data) |
543 | { | 545 | { |
544 | char *name = (char *)refname; | 546 | char *name = (char *)refname; |
545 | html_option(name, name, ctx.qry.head); | 547 | html_option(name, name, ctx.qry.head); |
546 | return 0; | 548 | return 0; |
547 | } | 549 | } |
548 | 550 | ||
549 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 551 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
550 | int flags, void *cb_data) | 552 | int flags, void *cb_data) |
551 | { | 553 | { |
552 | struct tag *tag; | 554 | struct tag *tag; |
553 | struct taginfo *info; | 555 | struct taginfo *info; |
554 | struct object *obj; | 556 | struct object *obj; |
555 | char buf[256], *url; | 557 | char buf[256], *url; |
556 | unsigned char fileid[20]; | 558 | unsigned char fileid[20]; |
557 | int *header = (int *)cb_data; | 559 | int *header = (int *)cb_data; |
558 | 560 | ||
559 | if (prefixcmp(refname, "refs/archives")) | 561 | if (prefixcmp(refname, "refs/archives")) |
560 | return 0; | 562 | return 0; |
561 | strncpy(buf, refname+14, sizeof(buf)); | 563 | strncpy(buf, refname+14, sizeof(buf)); |
562 | obj = parse_object(sha1); | 564 | obj = parse_object(sha1); |
563 | if (!obj) | 565 | if (!obj) |
564 | return 1; | 566 | return 1; |
565 | if (obj->type == OBJ_TAG) { | 567 | if (obj->type == OBJ_TAG) { |
566 | tag = lookup_tag(sha1); | 568 | tag = lookup_tag(sha1); |
567 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 569 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
568 | return 0; | 570 | return 0; |
569 | hashcpy(fileid, tag->tagged->sha1); | 571 | hashcpy(fileid, tag->tagged->sha1); |
570 | } else if (obj->type != OBJ_BLOB) { | 572 | } else if (obj->type != OBJ_BLOB) { |
571 | return 0; | 573 | return 0; |
572 | } else { | 574 | } else { |
573 | hashcpy(fileid, sha1); | 575 | hashcpy(fileid, sha1); |
574 | } | 576 | } |
575 | if (!*header) { | 577 | if (!*header) { |
576 | html("<h1>download</h1>\n"); | 578 | html("<h1>download</h1>\n"); |
577 | *header = 1; | 579 | *header = 1; |
578 | } | 580 | } |
579 | url = cgit_pageurl(ctx.qry.repo, "blob", | 581 | url = cgit_pageurl(ctx.qry.repo, "blob", |
580 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 582 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
581 | buf)); | 583 | buf)); |
582 | html_link_open(url, NULL, "menu"); | 584 | html_link_open(url, NULL, "menu"); |
583 | html_txt(strlpart(buf, 20)); | 585 | html_txt(strlpart(buf, 20)); |
584 | html_link_close(); | 586 | html_link_close(); |