repo_index.c (1243B)
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 free(index); 25 } 26 27 void gemini_repoindex_begin(GeminiRepoIndex* index) { 28 assert(index != NULL); 29 FILE* out = index->out; 30 fprintf(out, "# Repositories\n\n"); 31 } 32 33 void gemini_repoindex_add_repo(GeminiRepoIndex* index, const GitRepo* repo) { 34 assert(index != NULL); 35 assert(repo != NULL); 36 FILE* out = index->out; 37 fprintf(out, "=> "); 38 print_percent_encoded(out, repo->short_name); 39 fprintf(out, "/log.gmi %s", repo->short_name); 40 if (repo->description && repo->description[0] != '\0') { 41 fprintf(out, " - %s", repo->description); 42 } 43 if (repo->last_commit_time > 0) { 44 fprintf(out, " (last commit: "); 45 print_time_short(out, repo->last_commit_time); 46 fprintf(out, ")"); 47 } 48 fprintf(out, "\n"); 49 } 50 51 void gemini_repoindex_end(GeminiRepoIndex* index) { 52 assert(index != NULL); 53 (void)index; 54 }