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");
- for (int i = 0; i < currentPage->incoming->length; i++) {
- struct Page *page = currentPage->incoming->pages[i];
- char *link = concat_strings(5,
- " - permalink,
- "\">",
- page->title,
- "
\n"
- );
- strcat(incomingLinksList, link);
- free(link);
+ if (currentPage->incoming->length == 0) {
+ strcat(incomingLinksList, " - none
\n");
+ } else {
+ for (int i = 0; i < currentPage->incoming->length; i++) {
+ struct Page *page = currentPage->incoming->pages[i];
+ char *link = concat_strings(5,
+ " - permalink,
+ "\">",
+ page->title,
+ "
\n"
+ );
+ strcat(incomingLinksList, link);
+ free(link);
+ }
}
strcat(incomingLinksList, "
\n");