cld-ssg

The static site generator (to be) used for hellocld.com
git clone git://git.hellocld.com/cld-ssg
Log | Files | Refs

commit c8eff44d4284cc7e1fded80c32002532df5e0aa3
parent ac439af9554f1c43369d3ad49a9842625d84d7dc
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Sun, 29 Sep 2019 12:22:01 -0400

Multi-post generation working

Diffstat:
M.gitignore | 1+
Mconfig.h | 2+-
Mmain.c | 31+++++++++++++++++++++----------
Rtestdir/2019-09-24-20-24-real-test.md -> postdir/2019-09-24-20-24-real-test.md | 0
Apostdir/2019-09-29-12-15-another-test.md | 5+++++
Dtestdir/123 | 0
Dtestdir/201909042150-boop.md | 7-------
Dtestdir/201909042151-hello.md | 0
Dtestdir/thing | 0
9 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,3 +1,4 @@ +*.o *.sw[p,o] bin/* testhtml/* diff --git a/config.h b/config.h @@ -8,7 +8,7 @@ /* Root directory for the generated website */ #define HTMLDIR "testhtml/" /* Directory where .md posts are saved */ -#define POSTDIR "testdir/" +#define POSTDIR "postdir/" #define INDEX_POSTS 10 /* I should probably use some system defaults for these */ diff --git a/main.c b/main.c @@ -29,7 +29,6 @@ struct post *create_post(const char *file); char *get_post_title(struct cmark_node *root); struct tm *get_post_time(const char *file); void free_post(struct post *p); -int create_all_posts(struct post *posts); int write_index(struct post *posts, int totalPosts); int write_archive(struct post *posts, int totalPosts); @@ -43,24 +42,36 @@ int main() /* Load header and footer html */ - /* Create website directories */ - /* Load all posts */ - - /* Write post HTML pages */ + struct dirent **t_mds; + int t_postcount = scandir(POSTDIR, &t_mds, md_filter, alphasort); + if(t_postcount < 0) { + printf("ERROR: Failed to load posts from %s\n", POSTDIR); + return -1; + } + + int i = t_postcount; + struct post *posts[t_postcount]; + while(i--) { + posts[i] = create_post(t_mds[i]->d_name); + /* Since we're already iterating through, write the post now */ + write_post(posts[i]); + } + + + /* Write index.html */ /* Write archive.html */ /* Copy images/videos/audio/static pages */ - printf("*** read_file testing ***\n\n"); - struct post *tp = create_post("2019-09-24-20-24-real-test.md"); - - write_post(tp); - free_post(tp); + /* free up all the posts on the heap */ + i = t_postcount; + while(i--) + free_post(posts[i]); return 0; } diff --git a/testdir/2019-09-24-20-24-real-test.md b/postdir/2019-09-24-20-24-real-test.md diff --git a/postdir/2019-09-29-12-15-another-test.md b/postdir/2019-09-29-12-15-another-test.md @@ -0,0 +1,5 @@ +# Another Test + +Yep, it's another test post. This is for trying out the whole loading a bunch of posts and generating HTML files bit. + +If it works, it's another solid step forward! diff --git a/testdir/123 b/testdir/123 diff --git a/testdir/201909042150-boop.md b/testdir/201909042150-boop.md @@ -1,7 +0,0 @@ -# A Test -I'm a test file! :) Look at `some code`, see something *important*. - -It's all here! -- Pretty cool, right? -- Yes, very cool. -- [Links are **cooler**](https://hellocld.com) diff --git a/testdir/201909042151-hello.md b/testdir/201909042151-hello.md diff --git a/testdir/thing b/testdir/thing