From 04ade4f784565a2c3070e0457d987468d6201b3e Mon Sep 17 00:00:00 2001
From: "Rafael G. Martins"
Date: Wed, 1 May 2019 23:21:19 +0200
Subject: Revert "make: support posts autoloading"
It works mostly fine, but if you build a website, delete some files and
try to rebuild, it won't be able to detect the removed files. This may
be reverted when I find a solution for this problem.
This reverts commit 792ac4ec66dd098109a88065420ef95c1a78624f.
---
man/blogcfile.5.ronn | 9 --
src/blogc-make/ctx.c | 108 +-------------
src/blogc-make/ctx.h | 3 -
src/blogc-make/rules.c | 48 +++----
src/blogc-make/settings.c | 1 -
tests/blogc-make/check_blogc_make.sh.in | 248 --------------------------------
6 files changed, 24 insertions(+), 393 deletions(-)
diff --git a/man/blogcfile.5.ronn b/man/blogcfile.5.ronn
index b63bcf7..fd77e1c 100644
--- a/man/blogcfile.5.ronn
+++ b/man/blogcfile.5.ronn
@@ -110,12 +110,6 @@ however these rules can be customized with the following settings, from the
The prefix of the posts file names. It is used for both content and output
directories, and is relative to `content_dir` and the output directory.
- * `posts_autoload` (default: `false`):
- If true, blogc-make(1) will guess the source files from the posts directory
- (`content_dir`/`post_prefix`) and ignore anything listed in `[posts]` section.
- This setting automatically enable `posts_sort`, as there's no manually-provided
- order of posts to follow.
-
* `posts_per_page` (default: `10`):
Number of posts per page in the pagination pages. If negative, all the posts
are included. If `0`, no post listing pages are generated. Also, if negative or
@@ -147,9 +141,6 @@ is `foo`.
All the posts are relative to the `post_prefix` in the root of the website.
-This section can be omitted if using the `posts_autoload` setting, as it will
-guess the posts from the directory.
-
### Pages listing
The `[pages]` section is a listing of the pages that will be included in the
diff --git a/src/blogc-make/ctx.c b/src/blogc-make/ctx.c
index d7a503d..423b334 100644
--- a/src/blogc-make/ctx.c
+++ b/src/blogc-make/ctx.c
@@ -13,7 +13,6 @@
#include
#include
#include
-#include
#include
#include
#include
@@ -268,11 +267,7 @@ bm_ctx_new(bm_ctx_t *base, const char *settings_file, const char *argv0,
}
rv->posts_fctx = NULL;
- rv->posts_deleted = false;
- if (bc_str_to_bool(bc_trie_lookup(settings->settings, "posts_autoload"))) {
- bm_ctx_autoload_posts(rv);
- }
- else if (settings->posts != NULL) {
+ if (settings->posts != NULL) {
for (size_t i = 0; settings->posts[i] != NULL; i++) {
char *f = bm_generate_filename(content_dir, post_prefix,
settings->posts[i], source_ext);
@@ -311,7 +306,7 @@ bm_ctx_reload(bm_ctx_t **ctx)
if (*ctx == NULL || (*ctx)->settings_fctx == NULL)
return false;
- if ((*ctx)->posts_deleted || bm_filectx_changed((*ctx)->settings_fctx, NULL, NULL)) {
+ if (bm_filectx_changed((*ctx)->settings_fctx, NULL, NULL)) {
// reload everything! we could just reload settings_fctx, as this
// would force rebuilding everything, but we need to know new/deleted
// files
@@ -333,13 +328,8 @@ bm_ctx_reload(bm_ctx_t **ctx)
bm_filectx_reload((*ctx)->atom_template_fctx);
bm_filectx_reload((*ctx)->listing_entry_fctx);
- if (bc_str_to_bool(bm_ctx_settings_lookup(*ctx, "posts_autoload"))) {
- bm_ctx_autoload_posts(*ctx);
- }
- else {
- for (bc_slist_t *tmp = (*ctx)->posts_fctx; tmp != NULL; tmp = tmp->next)
- bm_filectx_reload((bm_filectx_t*) tmp->data);
- }
+ for (bc_slist_t *tmp = (*ctx)->posts_fctx; tmp != NULL; tmp = tmp->next)
+ bm_filectx_reload((bm_filectx_t*) tmp->data);
for (bc_slist_t *tmp = (*ctx)->pages_fctx; tmp != NULL; tmp = tmp->next)
bm_filectx_reload((bm_filectx_t*) tmp->data);
@@ -351,96 +341,6 @@ bm_ctx_reload(bm_ctx_t **ctx)
}
-void
-bm_ctx_autoload_posts(bm_ctx_t *ctx)
-{
- if (ctx == NULL)
- return;
-
- const char *content_dir = bm_ctx_settings_lookup(ctx, "content_dir");
- const char *post_prefix = bm_ctx_settings_lookup(ctx, "post_prefix");
- const char *source_ext = bm_ctx_settings_lookup(ctx, "source_ext");
-
- char *posts_dir = bm_generate_filename(content_dir, post_prefix, NULL, NULL);
- char *abs_posts_dir = bc_strdup_printf("%s/%s", ctx->root_dir, posts_dir);
- DIR *dir = opendir(abs_posts_dir);
- if (dir == NULL) {
- fprintf(stderr,
- "blogc-make: warning: failed to open directory for posts autoload "
- "(%s): %s\n", abs_posts_dir, strerror(errno));
- free(posts_dir);
- free(abs_posts_dir);
- return;
- }
- free(abs_posts_dir);
-
- // trick 0: avoid additional loops if we are not reloading
- bool reloading = ctx->posts_fctx != NULL;
-
- // trick 1: set all the post file contexts as unreadable, so we can detect
- // which ones were deleted.
- for (bc_slist_t *tmp = ctx->posts_fctx; tmp != NULL; tmp = tmp->next) {
- bm_filectx_t *fc = tmp->data;
- if (fc->readable) {
- fc->readable = false;
- }
- }
-
- struct dirent *e;
- while (NULL != (e = readdir(dir))) {
- if ((0 == strcmp(e->d_name, ".")) || (0 == strcmp(e->d_name, "..")))
- continue;
- if (!bc_str_ends_with(e->d_name, source_ext))
- continue;
- char *tmp = bc_strdup_printf("%s/%s", posts_dir, e->d_name);
-
- // trick 2: if the file context exists in the index, just set it as
- // readable
- bm_filectx_t *fc = NULL;
- if (reloading) {
- for (bc_slist_t *t = ctx->posts_fctx; t != NULL; t = t->next) {
- bm_filectx_t *fct = t->data;
- if (0 == strcmp(fct->short_path, tmp)) {
- fc = fct;
- break;
- }
- }
- }
- if (fc != NULL) {
- fc->readable = true;
- bm_filectx_reload(fc);
- }
- else {
- e->d_name[strlen(e->d_name) - strlen(source_ext)] = 0;
- fc = bm_filectx_new(ctx, tmp, e->d_name, NULL);
- ctx->posts_fctx = bc_slist_append(ctx->posts_fctx, fc);
- }
- free(tmp);
- }
-
- // trick 3: delete the unreadable file contexts
- ctx->posts_deleted = false;
- if (reloading) {
- for (bc_slist_t *tmp = ctx->posts_fctx; tmp != NULL;) {
- bm_filectx_t *fc = tmp->data;
- if (!fc->readable) {
- bc_slist_t *next = tmp->next;
- ctx->posts_fctx = bc_slist_remove(ctx->posts_fctx, tmp,
- (bc_free_func_t) bm_filectx_free);
- tmp = next;
- ctx->posts_deleted = true;
- }
- else {
- tmp = tmp->next;
- }
- }
- }
-
- closedir(dir);
- free(posts_dir);
-}
-
-
void
bm_ctx_free_internal(bm_ctx_t *ctx)
{
diff --git a/src/blogc-make/ctx.h b/src/blogc-make/ctx.h
index 43284a5..a66d51c 100644
--- a/src/blogc-make/ctx.h
+++ b/src/blogc-make/ctx.h
@@ -63,10 +63,8 @@ typedef struct {
bm_filectx_t *listing_entry_fctx;
bc_slist_t *posts_fctx;
- bool posts_deleted;
bc_slist_t *pages_fctx;
bc_slist_t *copy_fctx;
-
} bm_ctx_t;
bm_filectx_t* bm_filectx_new(bm_ctx_t *ctx, const char *filename, const char *slug,
@@ -78,7 +76,6 @@ void bm_filectx_free(bm_filectx_t *fctx);
bm_ctx_t* bm_ctx_new(bm_ctx_t *base, const char *settings_file,
const char *argv0, bc_error_t **err);
bool bm_ctx_reload(bm_ctx_t **ctx);
-void bm_ctx_autoload_posts(bm_ctx_t *ctx);
void bm_ctx_free_internal(bm_ctx_t *ctx);
void bm_ctx_free(bm_ctx_t *ctx);
const char* bm_ctx_settings_lookup(bm_ctx_t *ctx, const char *key);
diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c
index f42b99a..96cf51d 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -32,9 +32,7 @@ posts_ordering(bm_ctx_t *ctx, bc_trie_t *variables, const char *variable)
const char *value = bm_ctx_settings_lookup_str(ctx, variable);
bool asc = 0 == strcasecmp(value, "asc");
- bool posts_autoload = bc_str_to_bool(bm_ctx_settings_lookup(ctx, "posts_autoload"));
- bool posts_sort = bc_str_to_bool(bm_ctx_settings_lookup(ctx, "posts_sort"));
- bool sort = posts_sort || posts_autoload;
+ bool sort = bc_str_to_bool(bm_ctx_settings_lookup(ctx, "posts_sort"));
if (sort) {
bc_trie_insert(variables, "FILTER_SORT", bc_strdup("1"));
@@ -77,7 +75,7 @@ posts_pagination_enabled(bm_ctx_t *ctx, const char *variable)
static bc_slist_t*
index_outputlist(bm_ctx_t *ctx)
{
- if (ctx == NULL || ctx->posts_fctx == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
if (!posts_pagination_enabled(ctx, "posts_per_page"))
@@ -99,7 +97,7 @@ index_outputlist(bm_ctx_t *ctx)
static int
index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
{
- if (ctx == NULL || ctx->posts_fctx == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
@@ -116,8 +114,7 @@ index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
- if (ctx->posts_deleted ||
- bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
+ if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->listing_entry_fctx, ctx->main_template_fctx, fctx, false))
{
rv = bm_exec_blogc(ctx, variables, NULL, true, ctx->listing_entry_fctx,
@@ -138,7 +135,7 @@ index_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
static bc_slist_t*
atom_outputlist(bm_ctx_t *ctx)
{
- if (ctx == NULL || ctx->posts_fctx == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
if (!posts_pagination_enabled(ctx, "atom_posts_per_page"))
@@ -160,7 +157,7 @@ atom_outputlist(bm_ctx_t *ctx)
static int
atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
{
- if (ctx == NULL || ctx->posts_fctx == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
@@ -176,8 +173,7 @@ atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
bm_filectx_t *fctx = l->data;
if (fctx == NULL)
continue;
- if (ctx->posts_deleted ||
- bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx, NULL, NULL,
+ if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx, NULL, NULL,
fctx, false))
{
rv = bm_exec_blogc(ctx, variables, NULL, true, NULL, ctx->atom_template_fctx,
@@ -198,7 +194,7 @@ atom_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
static bc_slist_t*
atom_tags_outputlist(bm_ctx_t *ctx)
{
- if (ctx == NULL || ctx->posts_fctx == NULL || ctx->settings->tags == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return NULL;
if (!posts_pagination_enabled(ctx, "atom_posts_per_page"))
@@ -222,7 +218,7 @@ atom_tags_outputlist(bm_ctx_t *ctx)
static int
atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
{
- if (ctx == NULL || ctx->posts_fctx == NULL || ctx->settings->tags == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return 0;
int rv = 0;
@@ -243,8 +239,7 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
bc_trie_insert(variables, "FILTER_TAG",
bc_strdup(ctx->settings->tags[i]));
- if (ctx->posts_deleted ||
- bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx, NULL, NULL,
+ if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx, NULL, NULL,
fctx, false))
{
rv = bm_exec_blogc(ctx, variables, NULL, true, NULL, ctx->atom_template_fctx,
@@ -265,7 +260,7 @@ atom_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
static bc_slist_t*
pagination_outputlist(bm_ctx_t *ctx)
{
- if (ctx == NULL || ctx->posts_fctx == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
// not using posts_pagination_enabled() here because we need to calculate
@@ -298,7 +293,7 @@ pagination_outputlist(bm_ctx_t *ctx)
static int
pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
{
- if (ctx == NULL || ctx->posts_fctx == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
@@ -320,8 +315,7 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
if (fctx == NULL)
continue;
bc_trie_insert(variables, "FILTER_PAGE", bc_strdup_printf("%zu", page));
- if (ctx->posts_deleted ||
- bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
+ if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->listing_entry_fctx, ctx->main_template_fctx, fctx, false))
{
rv = bm_exec_blogc(ctx, variables, NULL, true, ctx->listing_entry_fctx,
@@ -342,7 +336,7 @@ pagination_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
static bc_slist_t*
posts_outputlist(bm_ctx_t *ctx)
{
- if (ctx == NULL || ctx->posts_fctx == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL)
return NULL;
bc_slist_t *rv = NULL;
@@ -350,10 +344,9 @@ posts_outputlist(bm_ctx_t *ctx)
const char *post_prefix = bm_ctx_settings_lookup(ctx, "post_prefix");
const char *html_ext = bm_ctx_settings_lookup(ctx, "html_ext");
- for (bc_slist_t *l = ctx->posts_fctx; l != NULL; l = l->next) {
- bm_filectx_t *fc = l->data;
+ for (size_t i = 0; ctx->settings->posts[i] != NULL; i++) {
char *f = bm_generate_filename(ctx->short_output_dir, post_prefix,
- fc->slug, html_ext);
+ ctx->settings->posts[i], html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(f);
}
@@ -364,7 +357,7 @@ posts_outputlist(bm_ctx_t *ctx)
static int
posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
{
- if (ctx == NULL || ctx->posts_fctx == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL)
return 0;
int rv = 0;
@@ -410,7 +403,7 @@ posts_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
static bc_slist_t*
tags_outputlist(bm_ctx_t *ctx)
{
- if (ctx == NULL || ctx->posts_fctx == NULL || ctx->settings->tags == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return NULL;
if (!posts_pagination_enabled(ctx, "posts_per_page"))
@@ -434,7 +427,7 @@ tags_outputlist(bm_ctx_t *ctx)
static int
tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
{
- if (ctx == NULL || ctx->posts_fctx == NULL || ctx->settings->tags == NULL)
+ if (ctx == NULL || ctx->settings->posts == NULL || ctx->settings->tags == NULL)
return 0;
int rv = 0;
@@ -456,8 +449,7 @@ tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
bc_trie_insert(variables, "FILTER_TAG",
bc_strdup(ctx->settings->tags[i]));
- if (ctx->posts_deleted ||
- bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
+ if (bm_rule_need_rebuild(ctx->posts_fctx, ctx->settings_fctx,
ctx->listing_entry_fctx, ctx->main_template_fctx, fctx, false))
{
rv = bm_exec_blogc(ctx, variables, NULL, true, ctx->listing_entry_fctx,
diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c
index 2f56d9c..be976e3 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -28,7 +28,6 @@ static const struct default_settings_map {
{"main_template", "main.tmpl"},
{"source_ext", ".txt"},
{"listing_entry", NULL},
- {"posts_autoload", NULL},
{"posts_sort", NULL},
// pagination
diff --git a/tests/blogc-make/check_blogc_make.sh.in b/tests/blogc-make/check_blogc_make.sh.in
index d171027..36dfceb 100755
--- a/tests/blogc-make/check_blogc_make.sh.in
+++ b/tests/blogc-make/check_blogc_make.sh.in
@@ -755,254 +755,6 @@ diff -uN "${TEMP}/proj/_build/post/post11/index.html" "${TEMP}/expected-post-pos
rm -rf "${TEMP}/proj/_build"
-### default settings with some posts, order asc, posts_autoload
-
-mkdir -p "${TEMP}/proj/content/post2"
-
-cat > "${TEMP}/proj/content/post2/foo.txt" < "${TEMP}/proj/content/post2/bar.txt" < "${TEMP}/proj/blogcfile" <&1 | tee "${TEMP}/output.txt"
-grep "_build/index\\.html" "${TEMP}/output.txt"
-grep "_build/atom\\.xml" "${TEMP}/output.txt"
-grep "_build/page/1/index\\.html" "${TEMP}/output.txt"
-grep "_build/post2/foo/index\\.html" "${TEMP}/output.txt"
-grep "_build/post2/bar/index\\.html" "${TEMP}/output.txt"
-
-rm "${TEMP}/output.txt"
-
-cat > "${TEMP}/expected-index.html" < "${TEMP}/expected-atom.xml" <
-
- Lol's Website
- http://example.org/atom.xml
- 2016-09-01T00:00:00Z
-
-
-
- Lol
- author@example.com
-
- WAT?!
-
-
- Bar
- http://example.org/post2/bar/index.html
- 2016-09-01T00:00:00Z
- 2016-09-01T00:00:00Z
-
-
- Lol
- author@example.com
-
- This is bar.
-]]>
-
-
-
- Foo
- http://example.org/post2/foo/index.html
- 2016-10-01T00:00:00Z
- 2016-10-01T00:00:00Z
-
-
- Lol
- author@example.com
-
- This is foo.
-]]>
-
-
-
-EOF
-diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"
-
-cat > "${TEMP}/expected-post-foo.html" <This is foo.
-
-
-EOF
-diff -uN "${TEMP}/proj/_build/post2/foo/index.html" "${TEMP}/expected-post-foo.html"
-
-cat > "${TEMP}/expected-post-bar.html" <This is bar.
-
-
-EOF
-diff -uN "${TEMP}/proj/_build/post2/bar/index.html" "${TEMP}/expected-post-bar.html"
-
-rm -rf "${TEMP}/proj/_build" "${TEMP}/proj/content/post2"
-
-
-### default settings with some posts, order desc, posts_autoload
-
-mkdir -p "${TEMP}/proj/content/post2"
-
-cat > "${TEMP}/proj/content/post2/foo.txt" < "${TEMP}/proj/content/post2/bar.txt" < "${TEMP}/proj/blogcfile" <&1 | tee "${TEMP}/output.txt"
-grep "_build/index\\.html" "${TEMP}/output.txt"
-grep "_build/atom\\.xml" "${TEMP}/output.txt"
-grep "_build/page/1/index\\.html" "${TEMP}/output.txt"
-grep "_build/post2/foo/index\\.html" "${TEMP}/output.txt"
-grep "_build/post2/bar/index\\.html" "${TEMP}/output.txt"
-
-rm "${TEMP}/output.txt"
-
-cat > "${TEMP}/expected-index.html" < "${TEMP}/expected-atom.xml" <
-
- Lol's Website
- http://example.org/atom.xml
- 2016-09-01T00:00:00Z
-
-
-
- Lol
- author@example.com
-
- WAT?!
-
-
- Bar
- http://example.org/post2/bar/index.html
- 2016-09-01T00:00:00Z
- 2016-09-01T00:00:00Z
-
-
- Lol
- author@example.com
-
- This is bar.
-]]>
-
-
-
- Foo
- http://example.org/post2/foo/index.html
- 2016-08-01T00:00:00Z
- 2016-08-01T00:00:00Z
-
-
- Lol
- author@example.com
-
- This is foo.
-]]>
-
-
-
-EOF
-diff -uN "${TEMP}/proj/_build/atom.xml" "${TEMP}/expected-atom.xml"
-
-cat > "${TEMP}/expected-post-foo.html" <This is foo.
-
-
-EOF
-diff -uN "${TEMP}/proj/_build/post2/foo/index.html" "${TEMP}/expected-post-foo.html"
-
-cat > "${TEMP}/expected-post-bar.html" <This is bar.
-
-
-EOF
-diff -uN "${TEMP}/proj/_build/post2/bar/index.html" "${TEMP}/expected-post-bar.html"
-
-rm -rf "${TEMP}/proj/_build" "${TEMP}/proj/content/post2"
-
-
### default settings with some posts, order asc, posts_sort
cat > "${TEMP}/proj/blogcfile" <