repo_index.c (1264B)
1 #include "writer/gemini/repo_index.h" 2 3 #include <assert.h> 4 #include <stdlib.h> 5 6 #include "format.h" 7 #include "utils.h" 8 9 struct GeminiRepoIndex { 10 FILE* out; 11 }; 12 13 GeminiRepoIndex* gemini_repoindex_create(FILE* out) { 14 assert(out != NULL); 15 GeminiRepoIndex* index = ecalloc(1, sizeof(GeminiRepoIndex)); 16 index->out = out; 17 return index; 18 } 19 20 void gemini_repoindex_free(GeminiRepoIndex* index) { 21 if (!index) { 22 return; 23 } 24 index->out = NULL; 25 free(index); 26 } 27 28 void gemini_repoindex_begin(GeminiRepoIndex* index) { 29 assert(index != NULL); 30 FILE* out = index->out; 31 fprintf(out, "# Repositories\n\n"); 32 } 33 34 void gemini_repoindex_add_repo(GeminiRepoIndex* index, const GitRepo* repo) { 35 assert(index != NULL); 36 assert(repo != NULL); 37 FILE* out = index->out; 38 fprintf(out, "=> "); 39 print_percent_encoded(out, repo->short_name); 40 fprintf(out, "/log.gmi %s", repo->short_name); 41 if (repo->description && repo->description[0] != '\0') { 42 fprintf(out, " - %s", repo->description); 43 } 44 if (repo->last_commit_time > 0) { 45 fprintf(out, " (last commit: "); 46 print_time_short(out, repo->last_commit_time); 47 fprintf(out, ")"); 48 } 49 fprintf(out, "\n"); 50 } 51 52 void gemini_repoindex_end(GeminiRepoIndex* index) { 53 assert(index != NULL); 54 (void)index; 55 }