Make incoming link list display none if there's nothing
This commit is contained in:
parent
8dd7876ebc
commit
7f78f1db3c
42
calathea.c
42
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; // <ul class="calathea-incoming">\n</ul>\n
|
||||
for (int i = 0; i < currentPage->incoming->length; i++) {
|
||||
// ` <li><a href=\"[permalink]\">[title]</a></li>\n`
|
||||
struct Page *page = currentPage->incoming->pages[i];
|
||||
incomingListSize += 27 + strlen(page->title) + strlen(page->permalink);
|
||||
// <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++) {
|
||||
// ` <li><a href=\"[permalink]\">[title]</a></li>\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, "<ul class=\"calathea-incoming\">\n");
|
||||
for (int i = 0; i < currentPage->incoming->length; i++) {
|
||||
struct Page *page = currentPage->incoming->pages[i];
|
||||
char *link = concat_strings(5,
|
||||
" <li><a href=\"",
|
||||
page->permalink,
|
||||
"\">",
|
||||
page->title,
|
||||
"</a></li>\n"
|
||||
);
|
||||
strcat(incomingLinksList, link);
|
||||
free(link);
|
||||
if (currentPage->incoming->length == 0) {
|
||||
strcat(incomingLinksList, " <li>none</li>\n");
|
||||
} else {
|
||||
for (int i = 0; i < currentPage->incoming->length; i++) {
|
||||
struct Page *page = currentPage->incoming->pages[i];
|
||||
char *link = concat_strings(5,
|
||||
" <li><a href=\"",
|
||||
page->permalink,
|
||||
"\">",
|
||||
page->title,
|
||||
"</a></li>\n"
|
||||
);
|
||||
strcat(incomingLinksList, link);
|
||||
free(link);
|
||||
}
|
||||
}
|
||||
strcat(incomingLinksList, "</ul>\n");
|
||||
|
||||
|
|
Loading…
Reference in New Issue