cld-ssg

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

commit 8b3e27d7b7745aa9c4a8568e2b486ae611dead12
parent fe068712f9995934345959de91b30b5e00d89ddd
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Tue, 29 Oct 2019 15:23:49 -0400

Started working static page generation

Need a better name for these pages. They're written like posts, but not
included in the archive/index or given a post date/director

Diffstat:
Mconfig.h | 1+
Mmain.c | 23+++++++++++++++++++++--
Aposts/static-test.md | 2++
3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/config.h b/config.h @@ -25,3 +25,4 @@ #define MAX_TITLE_CHARS 1000 /* far is 18459 bytes as html */ #define MAX_URL_CHARS 1000 /* hellocld.com/2019/06/11/bitcrushed-5.html */ +#define STATIC_PAGE "static" diff --git a/main.c b/main.c @@ -25,6 +25,7 @@ struct post { char *content; char *desc; struct tm *time; + int is_static; }; /* Post generation functions */ @@ -39,6 +40,7 @@ int write_index(struct post *posts[], int totalPosts); int write_archive(struct post *posts[], int totalPosts); int write_rss(struct post *posts[], int totalPosts); int write_post(struct post *post); +int is_post_static(char *file); void copy_resources(char *); @@ -120,6 +122,10 @@ struct post *create_post(const char *file) printf("Loading post %s ... \n", buf); /* read in the post text file */ char *tmp = read_text(buf, MAX_POST_CHARS); + /* Check if it's a post or a static (other) page */ + p->is_static = is_post_static(p->fsource); + if(p->is_static) + printf("** Page %s is static\n", p->fsource); printf("Parsing post to cmark_node...\n"); struct cmark_node *t_root = cmark_parse_document( tmp, strlen(tmp), CMARK_OPT_UNSAFE); @@ -133,7 +139,8 @@ struct post *create_post(const char *file) /* generate the struct tm representing the post date */ p->time = get_post_time(file); printf("Inserting post time into cmark tree...\n"); - insert_post_time(t_root, p->time); + if(!p->is_static) + insert_post_time(t_root, p->time); printf("Rendering HTML...\n"); /* convert the markdown to html */ p->content = cmark_render_html(t_root, CMARK_OPT_UNSAFE); @@ -152,10 +159,14 @@ struct post *create_post(const char *file) printf("Generating html web directory...\n"); /* generate the base directory of the post */ p->dir = malloc(MAX_URL_CHARS); - sprintf(p->dir, "%d/%02d/%02d/", + if(!p->is_static) { + sprintf(p->dir, "%d/%02d/%02d/", p->time->tm_year + 1900, p->time->tm_mon, p->time->tm_mday); + + } else + sprintf(p->dir, ""); printf("Generation complete. Freeing node...\n"); cmark_node_free(t_root); return p; @@ -400,3 +411,11 @@ void copy_resources(char *dir) free(t_files); printf("-- Finished copying resources.\n"); } + +/* Checks if a file is a blog post or a static page */ +int is_post_static(char *file) +{ + if (strncmp(file, STATIC_PAGE, sizeof(STATIC_PAGE)) == 0) + return 1; + return 0; +} diff --git a/posts/static-test.md b/posts/static-test.md @@ -0,0 +1,2 @@ +# Static test +Testing the static page generator.