Make incoming link list display none if there's nothing

This commit is contained in:
Nat 2023-01-20 18:48:32 -08:00
parent 8dd7876ebc
commit 7f78f1db3c
Signed by: nat
GPG Key ID: B53AB05285D710D6
1 changed files with 26 additions and 16 deletions

View File

@ -478,17 +478,26 @@ int main(int argc, char *argv[]) {
char *incomingTagStart = strstr(renderedPage, "{{incoming}}"); char *incomingTagStart = strstr(renderedPage, "{{incoming}}");
if (incomingTagStart != NULL) { if (incomingTagStart != NULL) {
// Build the incoming links list // Build the incoming links list
int incomingListSize = 37; // <ul class="calathea-incoming">\n</ul>\n // <ul class="calathea-incoming">\n</ul>\n
int incomingListSize = 37;
if (currentPage->incoming->length == 0) {
// ` <li>none</li>\n`
incomingListSize += 16;
} else {
for (int i = 0; i < currentPage->incoming->length; i++) { for (int i = 0; i < currentPage->incoming->length; i++) {
// ` <li><a href=\"[permalink]\">[title]</a></li>\n` // ` <li><a href=\"[permalink]\">[title]</a></li>\n`
struct Page *page = currentPage->incoming->pages[i]; struct Page *page = currentPage->incoming->pages[i];
incomingListSize += 27 + strlen(page->title) + strlen(page->permalink); incomingListSize += 27 + strlen(page->title) + strlen(page->permalink);
} }
}
char *incomingLinksList = malloc((incomingListSize + 1) * sizeof(char)); char *incomingLinksList = malloc((incomingListSize + 1) * sizeof(char));
memset(incomingLinksList, 0, (incomingListSize + 1) * sizeof(char)); memset(incomingLinksList, 0, (incomingListSize + 1) * sizeof(char));
strcpy(incomingLinksList, "<ul class=\"calathea-incoming\">\n"); strcpy(incomingLinksList, "<ul class=\"calathea-incoming\">\n");
if (currentPage->incoming->length == 0) {
strcat(incomingLinksList, " <li>none</li>\n");
} else {
for (int i = 0; i < currentPage->incoming->length; i++) { for (int i = 0; i < currentPage->incoming->length; i++) {
struct Page *page = currentPage->incoming->pages[i]; struct Page *page = currentPage->incoming->pages[i];
char *link = concat_strings(5, char *link = concat_strings(5,
@ -501,6 +510,7 @@ int main(int argc, char *argv[]) {
strcat(incomingLinksList, link); strcat(incomingLinksList, link);
free(link); free(link);
} }
}
strcat(incomingLinksList, "</ul>\n"); strcat(incomingLinksList, "</ul>\n");
char *renderedWithInbound = substitute_string( char *renderedWithInbound = substitute_string(