diff options
author | Daniel Jones <admin@danieljon.es> | 2020-01-24 15:17:17 +1030 |
---|---|---|
committer | Daniel Jones <admin@danieljon.es> | 2020-01-24 15:17:17 +1030 |
commit | 8a8c6b1f8abcf911da9064a7c787c7673ec2df68 (patch) | |
tree | c963f7be1e2c765be4be4d615a8ea0d0d2b30674 | |
parent | 392a2d22951385257f23ef0af3070e6b0788a540 (diff) | |
download | websitegenerator-8a8c6b1f8abcf911da9064a7c787c7673ec2df68.tar.gz websitegenerator-8a8c6b1f8abcf911da9064a7c787c7673ec2df68.zip |
added pinned posts feature
-rw-r--r-- | config.h | 4 | ||||
-rw-r--r-- | pages.c | 51 | ||||
-rw-r--r-- | pages.h | 5 | ||||
-rw-r--r-- | template.txt | 1 |
4 files changed, 53 insertions, 8 deletions
@@ -22,6 +22,7 @@ enum flag { NONE = 0, RSS = 1, + PINNED = 2, }; struct page @@ -95,6 +96,7 @@ static const char *posts_output_dir = "posts/"; static const char *direct_output_dir = "posts/direct/"; static const int posts_per_page = 10; static const int ignore[] = {}; /* ignore these posts */ +static const int pinned[] = {107,104}; /* pinned posts */ /* rss */ static const char *rss_output = "posts/posts.rss"; @@ -114,7 +116,7 @@ static const struct page pages[] = { {opinions_animepage, NONE}, {opinions_everythingpage, NONE}, {portfoliopage, NONE}, - {postspage, RSS}, /* flag RSS to generate RSS feed */ + {postspage, RSS|PINNED}, /* flags: RSS feed, pinned posts */ }; #endif @@ -480,7 +480,12 @@ char fgets(buff, size, in); striphtml(buff, size); strncpy(title, buff, size); - + size_t len = strlen(title)-1; + while ((title[len] == ' ') || (title[len] == '\t') || (title[len] == '\n')) + { + title[len] = '\0'; + len = strlen(title)-1; + } fclose(in); return title; } @@ -557,7 +562,7 @@ char } int -writeposts(const int *posts, size_t totalposts, const char *outfile, int currentpage, int pagecount) +writeposts(const int *posts, size_t totalposts, const char *outfile, int currentpage, int pagecount, int flags) { /* * write posts into 'output_dir'/'outfile' @@ -590,6 +595,19 @@ writeposts(const int *posts, size_t totalposts, const char *outfile, int current return 0; } fprintf(tmp, "%s\n", pagebar); + if (flags & PINNED && currentpage == 1) + { + char pinned[4096] = {0}; + if (!generatepinned(pinned, 4096)) + { + fprintf(stderr, "unable to generate pinned section\n"); + } + else + { + fprintf(tmp, "%s\n", pinned); + } + } + for (int x = start; x < stop; x++) { /* @@ -633,7 +651,30 @@ writeposts(const int *posts, size_t totalposts, const char *outfile, int current } int -generatepostpages(const int *posts, size_t totalposts, int pagecount) +generatepinned(char *buff, size_t size) +{ + char title[64] = {0}; + char file[512] = {0}; + char outbuff[512] = {0}; + + strncat(buff, "\n<div class=\"pinned\">\nPinned posts:\n", 60); + + // pray we fit + for (int i = 0; i < sizeof(pinned)/sizeof(pinned[0]); i++) + { + snprintf(file, 512, "%s/%d.txt", posts_content, pinned[i]); + gettitle(file, title, 64); + snprintf(outbuff, 512, "<br><a href=\"direct/%d.html\">%s</a>\n",pinned[i], title); + strncat(buff, outbuff, 512); + } + + + strncat(buff, "\n</div>\n<br><br><br>\n", 29); + return 1; +} + +int +generatepostpages(const int *posts, size_t totalposts, int pagecount, int flags) { /* * create each blog page, there will be 'pagecount' of them @@ -659,7 +700,7 @@ generatepostpages(const int *posts, size_t totalposts, int pagecount) fprintf(stderr, "unable to create generic page '%s', unrecoverable failure\n", outfilename); return 0; } - if (!writeposts(posts, totalposts, outfilename, i, pagecount)) + if (!writeposts(posts, totalposts, outfilename, i, pagecount, flags)) { fprintf(stderr, "unable to create write posts to page %d', unrecoverable failure\n", i); return 0; @@ -725,7 +766,7 @@ postspage(int flags) /* determine how many pages we need, if total posts divided by 'posts_per_page' isn't 0, we need 'posts_per_page'+1 pages */ int pagecount = (totalposts%posts_per_page == 0) ? totalposts/posts_per_page : totalposts/posts_per_page+1; - if (!generatepostpages(posts, totalposts, pagecount)) + if (!generatepostpages(posts, totalposts, pagecount, flags)) { fprintf(stderr, "unable to create post pages, unrecoverable failure\n"); return 0; @@ -45,8 +45,9 @@ int postscompare(const void *a, const void *b); int genericpage(int flags, const char *ind, const char *out, const char *tit, const char *inf); int createdirectpages(const int *posts, size_t totalposts); char *generatepagebar(char *bar, size_t size, const int *posts, size_t totalposts, int currentpage, int pagecount); -int generatepostpages(const int *posts, size_t totalposts, int pagecount); -int writeposts(const int *posts, size_t totalposts, const char *outfile, int currentpage, int pagecount); +int generatepostpages(const int *posts, size_t totalposts, int pagecount, int flags); +int writeposts(const int *posts, size_t totalposts, const char *outfile, int currentpage, int pagecount, int flags); +int generatepinned(char *buff, size_t size); int generaterss(const int *posts, size_t totalposts); int writerss(FILE *out, int post); char *striphtml(char *str, size_t size); diff --git a/template.txt b/template.txt index b5abdaf..5e6e2a6 100644 --- a/template.txt +++ b/template.txt @@ -33,6 +33,7 @@ hr{border-color: black;} div.viewing{max-width: 70%; width: 100%; display: inline-block; margin: 10px;} div.cover{display:inline-block; vertical-align: top; padding-top: 28px; padding-left: 15px; padding-bottom: 20px;} .content{} +.pinned{margin-left: 10px; display: inline-block; border-width: 1px; width: auto; outline: 1px solid #000; outline-offset: 10px;} </style> </head> <body> |