gout

A static git page generator
git clone https://git.bracken.jp/gout.git
Log | Files | Refs | README | LICENSE

repo_index.c (2587B)


      1 #include "writer/html/repo_index.h"
      2 
      3 #include <assert.h>
      4 #include <stdlib.h>
      5 
      6 #include "format.h"
      7 #include "utils.h"
      8 
      9 struct HtmlRepoIndex {
     10   FILE* out;
     11   const char* me_url;
     12 };
     13 
     14 HtmlRepoIndex* html_repoindex_create(FILE* out) {
     15   assert(out != NULL);
     16   HtmlRepoIndex* index = ecalloc(1, sizeof(HtmlRepoIndex));
     17   index->out = out;
     18   index->me_url = NULL;
     19   return index;
     20 }
     21 
     22 void html_repoindex_free(HtmlRepoIndex* index) {
     23   if (!index) {
     24     return;
     25   }
     26   free(index);
     27 }
     28 
     29 void html_repoindex_set_me_url(HtmlRepoIndex* index, const char* url) {
     30   assert(index != NULL);
     31   index->me_url = url;
     32 }
     33 
     34 void html_repoindex_begin(HtmlRepoIndex* index) {
     35   assert(index != NULL);
     36   FILE* out = index->out;
     37   fprintf(
     38       out,
     39       "<!DOCTYPE html>\n"
     40       "<html>\n"
     41       "<head>\n"
     42       "<meta "
     43       "http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n"
     44       "<meta "
     45       "name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n"
     46       "<title>Repositories</title>\n"
     47       "<link rel=\"icon\" type=\"image/png\" href=\"favicon.png\" />\n"
     48       "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n");
     49   if (index->me_url) {
     50     fprintf(out, "<link rel=\"me\" href=\"");
     51     print_xml_encoded(out, index->me_url);
     52     fprintf(out, "\" />\n");
     53   }
     54   fprintf(
     55       out,
     56       "</head>\n"
     57       "<body>\n"
     58       "<table>\n<tr><td>"
     59       "<img src=\"logo.png\" alt=\"\" width=\"32\" height=\"32\" /></td>\n"
     60       "<td><span class=\"desc\">Repositories</span></td></tr>"
     61       "<tr><td></td><td>\n"
     62       "</td></tr>\n"
     63       "</table>\n<hr/>\n<div id=\"content\">\n"
     64       "<table id=\"index\"><thead>\n"
     65       "<tr><td><b>Name</b></td><td><b>Description</b></td><td><b>Owner</b></td>"
     66       "<td><b>Last commit</b></td></tr>"
     67       "</thead><tbody>\n");
     68 }
     69 
     70 void html_repoindex_add_repo(HtmlRepoIndex* index, const GitRepo* repo) {
     71   assert(index != NULL);
     72   assert(repo != NULL);
     73   FILE* out = index->out;
     74   fprintf(out, "<tr><td><a href=\"");
     75   print_percent_encoded(out, repo->short_name);
     76   fprintf(out, "/log.html\">");
     77   print_xml_encoded(out, repo->short_name);
     78   fprintf(out, "</a></td><td>");
     79   print_xml_encoded(out, repo->description);
     80   fprintf(out, "</td><td>");
     81   print_xml_encoded(out, repo->owner);
     82   fprintf(out, "</td><td>");
     83   if (repo->last_commit_time > 0) {
     84     print_time_short(out, repo->last_commit_time);
     85   }
     86   fprintf(out, "</td></tr>");
     87 }
     88 
     89 void html_repoindex_end(HtmlRepoIndex* index) {
     90   assert(index != NULL);
     91   FILE* out = index->out;
     92   fprintf(out, "</tbody>\n</table>\n</div>\n</body>\n</html>\n");
     93 }