fix doc example cache path

This commit is contained in:
root
2026-06-21 20:59:01 +00:00
parent 4eda629c8d
commit c0f3c5507c
2 changed files with 17 additions and 7 deletions
+14 -7
View File
@@ -45,9 +45,14 @@ void render_doc_params(StringList param_lines)
?></div></>
}
String doc_example_path(String page, u64 idx)
String doc_example_path(Request& context, String page, u64 idx)
{
return("examples/_gen/" + page + "_" + std::to_string(idx + 1) + ".uce");
String bin_dir = context.params["UCE_BIN_DIRECTORY"];
if(bin_dir == "")
return("");
String dir = path_join(bin_dir, "doc-examples");
mkdir(dir);
return(path_join(dir, page + "_" + std::to_string(idx + 1) + ".uce"));
}
String doc_example_unit_source(String body)
@@ -62,9 +67,11 @@ bool doc_write_if_changed(String path, String content)
return(file_put_contents(path, content));
}
String doc_render_example_output(String page, u64 idx, String body)
String doc_render_example_output(Request& context, String page, u64 idx, String body)
{
String path = doc_example_path(page, idx);
String path = doc_example_path(context, page, idx);
if(path == "")
return("DOC EXAMPLE ERROR: UCE_BIN_DIRECTORY is not available");
String unit_source = doc_example_unit_source(body);
if(!doc_write_if_changed(path, unit_source))
return("DOC EXAMPLE ERROR: could not write " + path);
@@ -79,12 +86,12 @@ String doc_render_example_output(String page, u64 idx, String body)
return(out);
}
void render_doc_examples(String page, StringList example_blocks)
void render_doc_examples(Request& context, String page, StringList example_blocks)
{
for(u64 idx = 0; idx < example_blocks.size(); idx++)
{
String body = example_blocks[idx];
String output = doc_render_example_output(page, idx, body);
String output = doc_render_example_output(context, page, idx, body);
?><div class="doc-section example">
<h3>Example</h3>
<pre class="example-source"><?= body ?></pre>
@@ -276,7 +283,7 @@ RENDER(Request& context)
?><div class="doc-section content"><?: markdown_to_html(doc_page.content) ?></div><?
}
render_doc_examples(page, doc_page.example_blocks);
render_doc_examples(context, page, doc_page.example_blocks);
?></article><?