aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2025-08-29 14:33:02 -0400
committerRaghuram Subramani <raghus2247@gmail.com>2025-08-29 14:33:02 -0400
commitf63235994855a3a6d71fb82f63b7b9d690ba5527 (patch)
tree4a28b22c1e3f870135a8ecc518ab3fc00e60ede8
parent5c726117f22d27ce46b7efefe9da6e39346efa09 (diff)
engine: handle eachdo with page as source if file is not a template
-rw-r--r--include/engine.h5
-rw-r--r--src/engine/eachdo.c13
-rw-r--r--src/engine/engine.c2
3 files changed, 17 insertions, 3 deletions
diff --git a/include/engine.h b/include/engine.h
index 5da3332..aec55b2 100644
--- a/include/engine.h
+++ b/include/engine.h
@@ -53,7 +53,10 @@ void handle_contentfor(char **buffer,
list_t *content_headers);
/* EACHDO */
-void handle_eachdo(char **buffer, key_match_t *match, directive_t *directive);
+void handle_eachdo(char **buffer,
+ key_match_t *match,
+ directive_t *directive,
+ config_t *config);
void handle_page_source(list_t *atoms,
eachdo_operands_t *operands,
list_t *directives,
diff --git a/src/engine/eachdo.c b/src/engine/eachdo.c
index 2d3ec4c..2b1cf07 100644
--- a/src/engine/eachdo.c
+++ b/src/engine/eachdo.c
@@ -159,6 +159,12 @@ handle_page_source(list_t *atoms,
list_t *directives,
config_t *config)
{
+ if (config == NULL) {
+ printf("EACHDO with page variables as a source will not work without "
+ "a config at the top of the file\n");
+ return;
+ }
+
list_t *nested_blocks
= unwrap(list_find_corresponding_value_from_ptr_wrapper(
config->keys, config->nested_config_values, trim(operands->key)));
@@ -186,7 +192,10 @@ handle_page_source(list_t *atoms,
* directive: Pointer to the directive struct
*/
void
-handle_eachdo(char **buffer, key_match_t *match, directive_t *directive)
+handle_eachdo(char **buffer,
+ key_match_t *match,
+ directive_t *directive,
+ config_t *config)
{
eachdo_operands_t *operands = directive->operands;
@@ -200,6 +209,8 @@ handle_eachdo(char **buffer, key_match_t *match, directive_t *directive)
if (!strcmp(operands->source, "resources"))
handle_file_source(atoms, operands, directives);
+ else if (!strcmp(operands->source, "page"))
+ handle_page_source(atoms, operands, directives, config);
else
printf("Unknown source: %s\n", operands->source);
diff --git a/src/engine/engine.c b/src/engine/engine.c
index 683d39b..d101791 100644
--- a/src/engine/engine.c
+++ b/src/engine/engine.c
@@ -108,7 +108,7 @@ engine_ingest(char **buffer, bool is_template)
if (is_template && !strcmp(operands->source, "page"))
skip++;
else
- handle_eachdo(buffer, match, directive);
+ handle_eachdo(buffer, match, directive, engine->config);
break;
}