ssnail

crappy and opinionated static site generator
git clone https://git.e1e0.net/ssnail.git
Log | Files | Refs | README | LICENSE

commit 49f0b3cfebe2c8faac8a093c74fd77b84cd5ba26
parent ebcdf1d86a6d1febb773741278cfff633fbf2013
Author: Paco Esteban <paco@e1e0.net>
Date:   Tue, 23 Jun 2020 15:05:51 +0200

remove index generation

Not sure I need it, and still have to thing about how to implement it IF
I finally do.

Diffstat:
Mssnail.c | 79+++----------------------------------------------------------------------------
1 file changed, 3 insertions(+), 76 deletions(-)

diff --git a/ssnail.c b/ssnail.c @@ -59,14 +59,13 @@ static void articleq_free(struct listhead *); static const struct ssnail_error *process_dir(char *, char *, int); static const struct ssnail_error *populate_article_entry(struct article *); static const struct ssnail_error *write_html(struct article *, char *, char *); -static const struct ssnail_error *generate_index(struct listhead *, char *, char *, char *); static int gen_html(struct article *); __dead static void usage(void) { - fprintf(stderr, "usage: %s [-F] [-f footer] [-h header] [-i] " + fprintf(stderr, "usage: %s [-F] [-f footer] [-h header] " "src_folder dst_folder\n", getprogname()); exit(1); } @@ -79,7 +78,7 @@ main(int argc, char *argv[]) struct article *ap = NULL; const struct ssnail_error *error = NULL; - int ch, force = 0, index = 0, needs_index = 0; + int ch, force = 0; char *srcdir = NULL, *dstdir = NULL, *fbuf = NULL; char *header_tpl = NULL, *footer_tpl = NULL; @@ -94,7 +93,7 @@ main(int argc, char *argv[]) goto done; } - while ((ch = getopt(argc, argv, "Ff:h:i")) != -1) { + while ((ch = getopt(argc, argv, "Ff:h:")) != -1) { switch (ch) { case 'F': force = 1; @@ -115,9 +114,6 @@ main(int argc, char *argv[]) goto done; } break; - case 'i': - index = 1; - break; default: usage(); } @@ -151,17 +147,9 @@ main(int argc, char *argv[]) error = write_html(ap, header_tpl, footer_tpl); if (error) goto done; - needs_index = 1; } } - if (index && (needs_index || force)) { - printf("Generate html index ... \n"); - error = generate_index(&head, header_tpl, footer_tpl, dstdir); - if (error) - goto done; - } - done: free(srcdir); free(dstdir); @@ -177,67 +165,6 @@ done: return EXIT_SUCCESS; } -static const struct ssnail_error * -generate_index(struct listhead *h, char *head_tpl, - char *foot_tpl, char *dst_dir) -{ - const struct ssnail_error *error = NULL; - struct article *a; - char *header = NULL, *footer = NULL; - FILE *fout; - time_t now; - struct tm *timeInfo; - char mytime[12], *index_path = NULL; - - time(&now); - timeInfo = localtime(&now); - if (strftime(mytime, sizeof(mytime), "%Y-%m-%d", timeInfo) == 0) { - error = ssnail_error_msg(2, "strftime"); - goto out; - } - - if (load_from_file(&header, head_tpl) == 0) { - error = ssnail_error_from_errno("load head_tpl"); - goto out; - } - header = str_rep(header, "$title$", "index"); - header = str_rep(header, "$author$", getlogin()); - header = str_rep(header, "$date$", mytime); - if (load_from_file(&footer, foot_tpl) == 0) { - error = ssnail_error_from_errno("load foot_tpl"); - goto out; - } - footer = str_rep(footer, "$title$", "index"); - - if ((index_path = build_full_path(dst_dir, "index.html")) == NULL) { - error = ssnail_error_msg(2, "build_path dst_dir"); - goto out; - } - if ((fout = fopen(index_path, "w")) == NULL) { - error = ssnail_error_msg(2, "fopen index"); - goto out; - } - fwrite(header, 1, strlen(header), fout); - /* TODO: make this list reverse date ordered */ - fprintf(fout, "<ul>\n"); - SLIST_FOREACH(a, h, entries) { - if (strcmp(a->type, "article") == 0) { - char *href = strchr(a->dst_path, '/') + 1; - fprintf(fout, "<li><a href=\"%s\">%s</a></li>\n", - href, a->title); - } - } - fprintf(fout, "</ul>\n"); - fwrite(footer, 1, strlen(footer), fout); - fclose(fout); - -out: - free(index_path); - free(header); - free(footer); - return error; -} - static void articleq_free(struct listhead *h) {