cld-ssg

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

commit bd28b464022f5f8c639615de775afa6502dc4565
parent b64dd31cf04f62420ccd9eca8b23e2a365d610d6
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Wed, 25 Sep 2019 18:31:41 -0400

Fails to make directory; look for 'recursive mkdir' for solutions

Diffstat:
MMakefile | 2+-
Mconfig.h | 4++--
Mmain.c | 55+++++++++++++++++++++++++++++++++++++------------------
3 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile @@ -2,7 +2,7 @@ CC = gcc CFLAGS = -g -Wall -pedantic CLIBS = -lcmark -default: dirs main.c +default: dirs main.c config.h $(CC) $(CFLAGS) main.c -o ./bin/cld-ssg $(CLIBS) dirs: diff --git a/config.h b/config.h @@ -6,9 +6,9 @@ */ /* Root directory for the generated website */ -#define HTMLDIR "./testhtml/" +#define HTMLDIR "testhtml/" /* Directory where .md posts are saved */ -#define POSTDIR "./testdir/" +#define POSTDIR "testdir/" #define INDEX_POSTS 10 /* I should probably use some system defaults for these */ diff --git a/main.c b/main.c @@ -5,6 +5,8 @@ #include <time.h> #include <stdio.h> #include <string.h> +#include <sys/stat.h> +#include <errno.h> #include "config.h" @@ -59,6 +61,9 @@ int main() struct post *tp = create_post(file); printf("File Path:\t%s\nPost Title:\t%s\nPost URL:\t%s\n%s\n", file, tp->title, tp->url, tp->content); + + write_post(tp); + free(tp->content); free(tp->title); free(tp); @@ -134,7 +139,7 @@ struct tm *get_post_time(const char *file) char *create_post_url(struct tm *time, char *title) { char *t_url = malloc(MAX_URL_CHARS); - sprintf(t_url, "/%d/%02d/%02d/%s.html", + sprintf(t_url, "%d/%02d/%02d/%s.html", time->tm_year + 1900, time->tm_mon, time->tm_mday, @@ -145,29 +150,20 @@ char *create_post_url(struct tm *time, char *title) return t_url; } -/* Generates all posts found in ./_posts; returns total number of posts */ -int create_all_posts(struct post *posts) -{ - -} - -/* Generates index.html using the latest posts */ -int create_index(struct post *posts, int totalPosts) +int write_post(struct post *post) { + char *dir = malloc(MAX_URL_CHARS); + sprintf(dir, "%s%s", HTMLDIR, post->url); -} + printf("DEBUG: %s\n", dir); -/* Generates archive.html using all posts */ -int create_archive(struct post *posts, int totalPosts) -{ + printf("%d\n", create_directory(dir)); + FILE *f = fopen(post->url, "w"); + fprintf(f, post->content); + fclose(f); } -/* Creates an rss feed from all posts */ -int create_rss(struct post *posts, int totalPosts) -{ - -} /* Reads a text file into a char* */ char *read_text(const char *path, int maxLength) @@ -182,3 +178,26 @@ char *read_text(const char *path, int maxLength) fclose(f); return o; } + +/* Creates a directory structure based on the path provided */ +int create_directory(const char *path) +{ + int status; + mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + status = errno; + /* + char t_buf[MAX_URL_CHARS] = ""; + char *dir = strtok(path, "/"); + do { + strcat(t_buf, dir); + strcat(t_buf, "/"); + mkdir(path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + status = errno; + printf("%s\t%d\n", t_buf, status); + dir = strtok(NULL, "/"); + } while (dir != NULL); + */ + + return status; +} +