From 7f78f1db3ccde59dfaf6e6389d61be7544d8a145 Mon Sep 17 00:00:00 2001 From: natjms Date: Fri, 20 Jan 2023 18:48:32 -0800 Subject: [PATCH] Make incoming link list display none if there's nothing --- calathea.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/calathea.c b/calathea.c index e53fb6b..a4b5d57 100644 --- a/calathea.c +++ b/calathea.c @@ -478,28 +478,38 @@ int main(int argc, char *argv[]) { char *incomingTagStart = strstr(renderedPage, "{{incoming}}"); if (incomingTagStart != NULL) { // Build the incoming links list - int incomingListSize = 37; // \n - for (int i = 0; i < currentPage->incoming->length; i++) { - // `
  • [title]
  • \n` - struct Page *page = currentPage->incoming->pages[i]; - incomingListSize += 27 + strlen(page->title) + strlen(page->permalink); + // \n + int incomingListSize = 37; + if (currentPage->incoming->length == 0) { + // `
  • none
  • \n` + incomingListSize += 16; + } else { + for (int i = 0; i < currentPage->incoming->length; i++) { + // `
  • [title]
  • \n` + struct Page *page = currentPage->incoming->pages[i]; + incomingListSize += 27 + strlen(page->title) + strlen(page->permalink); + } } char *incomingLinksList = malloc((incomingListSize + 1) * sizeof(char)); memset(incomingLinksList, 0, (incomingListSize + 1) * sizeof(char)); strcpy(incomingLinksList, "\n");