aboutsummaryrefslogtreecommitdiffstats
path: root/src/blogc-make
diff options
context:
space:
mode:
Diffstat (limited to 'src/blogc-make')
-rw-r--r--src/blogc-make/rules.c18
-rw-r--r--src/blogc-make/utils.c34
-rw-r--r--src/blogc-make/utils.h2
3 files changed, 40 insertions, 14 deletions
diff --git a/src/blogc-make/rules.c b/src/blogc-make/rules.c
index 591ad21..06223c0 100644
--- a/src/blogc-make/rules.c
+++ b/src/blogc-make/rules.c
@@ -367,24 +367,19 @@ pagination_tags_outputlist(bm_ctx_t *ctx)
bc_trie_free(local);
if (last_page == NULL)
- break;
+ continue;
long pages = strtol(last_page, NULL, 10);
free(last_page);
- char *prefix = bc_strdup_printf("%s/%s/%s", tag_prefix,
- ctx->settings->tags[k], pagination_prefix);
-
for (size_t i = 0; i < pages; i++) {
char *j = bc_strdup_printf("%d", i + 1);
- char *f = bm_generate_filename(ctx->short_output_dir, prefix,
- j, html_ext);
+ char *f = bm_generate_filename2(ctx->short_output_dir, tag_prefix,
+ ctx->settings->tags[k], pagination_prefix, j, html_ext);
rv = bc_slist_append(rv, bm_filectx_new(ctx, f, NULL, NULL));
free(j);
free(f);
}
-
- free(prefix);
}
bc_trie_free(variables);
@@ -425,16 +420,14 @@ pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
// tag and page from the file path right now :/
char *tag = NULL;
for (size_t i = 0; ctx->settings->tags[i] != NULL; i++) {
- char *prefix = bc_strdup_printf("%s/%s/%s", tag_prefix,
- ctx->settings->tags[i], pagination_prefix);
bool b = false;
// it is impossible to have more output files per tag than the whole
// amount of output pages
for (size_t k = 1; k <= bc_slist_length(outputs); k++) {
char *j = bc_strdup_printf("%d", k);
- char *f = bm_generate_filename(ctx->short_output_dir, prefix,
- j, html_ext);
+ char *f = bm_generate_filename2(ctx->short_output_dir, tag_prefix,
+ ctx->settings->tags[i], pagination_prefix, j, html_ext);
free(j);
if (0 == strcmp(fctx->short_path, f)) {
tag = ctx->settings->tags[i];
@@ -445,7 +438,6 @@ pagination_tags_exec(bm_ctx_t *ctx, bc_slist_t *outputs, bc_trie_t *args)
}
free(f);
}
- free(prefix);
if (b)
break;
}
diff --git a/src/blogc-make/utils.c b/src/blogc-make/utils.c
index 91b7b53..8f69e44 100644
--- a/src/blogc-make/utils.c
+++ b/src/blogc-make/utils.c
@@ -28,7 +28,7 @@ bm_generate_filename(const char *dir, const char *prefix, const char *fname,
bool have_ext = ext != NULL && ext[0] != '\0';
bool have_ext_noslash = have_ext && ext[0] != '/';
bool is_index = have_fname && have_ext && (
- (0 == strcmp(fname, "index")) && ext[0] == '/');
+ (0 == strcmp(fname, "index")) && ext[0] == '/') && !have_prefix;
bc_string_t *rv = bc_string_new();
@@ -70,6 +70,38 @@ bm_generate_filename(const char *dir, const char *prefix, const char *fname,
char*
+bm_generate_filename2(const char *dir, const char *prefix, const char *fname,
+ const char *prefix2, const char *fname2, const char *ext)
+{
+ bool have_prefix = prefix != NULL && prefix[0] != '\0';
+ bool have_fname = fname != NULL && fname[0] != '\0';
+ bool have_prefix2 = prefix2 != NULL && prefix2[0] != '\0';
+
+ bc_string_t *p = bc_string_new();
+
+ if (have_prefix)
+ bc_string_append(p, prefix);
+
+ if (have_prefix && (have_fname || have_prefix2))
+ bc_string_append_c(p, '/');
+
+ if (have_fname)
+ bc_string_append(p, fname);
+
+ if (have_fname && have_prefix2)
+ bc_string_append_c(p, '/');
+
+ if (have_prefix2)
+ bc_string_append(p, prefix2);
+
+ char *rv = bm_generate_filename(dir, p->str, fname2, ext);
+ bc_string_free(p, true);
+
+ return rv;
+}
+
+
+char*
bm_abspath(const char *path, bc_error_t **err)
{
if (err == NULL || *err != NULL)
diff --git a/src/blogc-make/utils.h b/src/blogc-make/utils.h
index 5353c01..cbcfc0e 100644
--- a/src/blogc-make/utils.h
+++ b/src/blogc-make/utils.h
@@ -13,6 +13,8 @@
char* bm_generate_filename(const char *dir, const char *prefix, const char *fname,
const char *ext);
+char* bm_generate_filename2(const char *dir, const char *prefix, const char *fname,
+ const char *prefix2, const char *fname2, const char *ext);
char* bm_abspath(const char *path, bc_error_t **err);
#endif /* _MAKE_UTILS_H */