From 237fdfd41af9c0e02652663e5e2fdc5608586ee8 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Thu, 2 Jan 2020 12:15:07 +1030 Subject: direct post pages generate now --- config.h | 1 + pages.c | 57 +++++++++++++++++++++++++++++++++++++++++++++------------ pages.h | 1 + 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/config.h b/config.h index 326e7bb..9f40ef3 100644 --- a/config.h +++ b/config.h @@ -90,6 +90,7 @@ static const char *posts_title = "Daniel's posts"; static const char *posts_info = "

Posts

My posts about programming and things.
Date format is day/month/year because I'm sane.

"; static const char *posts_content = "content/blog/"; 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 */ diff --git a/pages.c b/pages.c index 86a30f0..56ff50c 100644 --- a/pages.c +++ b/pages.c @@ -466,6 +466,47 @@ postscompare(const void *a, const void *b) return (*(int *)a - *(int *)b); } +int +createdirectpages(int *posts, size_t totalposts) +{ + /* + * create direct post files for each post + */ + + char file[512]; + char source[512]; + char buff[128]; + for (int x = 1; x < totalposts; x++) + { + memset(source, 0, 1); + memset(file, 0, 1); + memset(buff, 0, 1); + /* output file */ + strcat(file, direct_output_dir); + sprintf(buff, "%d.html", posts[x]); + strcat(file, buff); + + /* source file */ + strcat(source, posts_content); + sprintf(buff, "%d.txt", posts[x]); + strcat(source, buff); + + if (!createfile(file)) + { + fprintf(stderr, "unable to create file '%s', unrecoverable failure\n", file); + return 0; + } + + if (!genericpage(NONE, file, source, posts_title, posts_info)) + { + fprintf(stderr, "unable to generate direct post page '%s', unrecoverable failure\n", file); + return 0; + } + //printf("%d\n", posts[x]); + } + return 1; +} + int postspage(int flags) { @@ -512,19 +553,11 @@ postspage(int flags) /* sort posts */ qsort(posts, totalposts, sizeof(int), postscompare); - char file[512]; - char buff[128]; - for (int x = 1; x < totalposts; x++) + + if (!createdirectpages(posts, totalposts)) { - memset(file, 0, 1); - memset(buff, 0, 1); - strcat(file, posts_output_dir); - sprintf(buff, "%d", posts[x]); - strcat(file, buff); - strcat(file, ".txt"); - //puts(file); - createfile(file); - //printf("%d\n", posts[x]); + fprintf(stderr, "unable to create direct post pages, unrecoverable failure\n"); + return 0; } return 1; diff --git a/pages.h b/pages.h index ad98eeb..e61eeb4 100644 --- a/pages.h +++ b/pages.h @@ -42,6 +42,7 @@ int createtmpfile(const char *name, const char *content, size_t size); int makedirectories(const char *basedir, const char *file); 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(int *posts, size_t totalposts); /* generators (to be put into the pages array) */ int frontpage(int flags); -- cgit v1.2.3