fix subfolder generation

This commit is contained in:
Luke Boswell 2023-03-17 12:58:40 +11:00
parent 03443ec328
commit c7f8ba6ded
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
5 changed files with 8 additions and 4 deletions

View file

@ -1,3 +1,4 @@
/output/*.html /output/*.html
/output/subFolder
/static-site /static-site
/bin /bin

View file

@ -61,4 +61,5 @@ Herculei undae calcata inmeriti quercus ignes parabant iam.
```roc ```roc
codeExample.roc codeExample.roc
``` ```

View file

@ -226,7 +226,7 @@ fn process_file(input_dir: &Path, output_dir: &Path, input_file: &Path) -> Resul
} }
pulldown_cmark::Event::End(pulldown_cmark::Tag::CodeBlock(_)) => { pulldown_cmark::Event::End(pulldown_cmark::Tag::CodeBlock(_)) => {
if in_code_block { if in_code_block {
match replace_code_with_static_file(&code_to_highlight, input_dir) { match replace_code_with_static_file(&code_to_highlight, input_file) {
None => {} None => {}
// Check if the code block is actually just a relative // Check if the code block is actually just a relative
// path to a static file, if so replace the code with // path to a static file, if so replace the code with
@ -327,10 +327,12 @@ fn is_roc_code_block(cbk: &pulldown_cmark::CodeBlockKind) -> bool {
} }
} }
fn replace_code_with_static_file(code: &str, input_dir: &Path) -> Option<String> { fn replace_code_with_static_file(code: &str, input_file: &Path) -> Option<String> {
let input_dir = input_file.parent()?;
let trimmed_code = code.trim(); let trimmed_code = code.trim();
if trimmed_code.len() <= 255 && trimmed_code.contains(".") { if trimmed_code.len() <= 255 && trimmed_code.contains(".") {
let file_path = input_dir.join(trimmed_code); let file_path = input_dir.join(trimmed_code);
let vec_u8 = fs::read(file_path).ok()?; let vec_u8 = fs::read(file_path).ok()?;
String::from_utf8(vec_u8).ok() String::from_utf8(vec_u8).ok()

View file

@ -14,7 +14,7 @@ NavLink : {
navLinks : List NavLink navLinks : List NavLink
navLinks = [ navLinks = [
{ url: "apple.html", title: "Exempli Gratia Pagina Pomi", text: "Apple" }, { url: "subFolder/apple.html", title: "Exempli Gratia Pagina Pomi", text: "Apple" },
{ url: "banana.html", title: "Exempli Gratia Pagina Musa", text: "Banana" }, { url: "banana.html", title: "Exempli Gratia Pagina Musa", text: "Banana" },
{ url: "cherry.html", title: "Exempli Pagina Cerasus", text: "Cherry" }, { url: "cherry.html", title: "Exempli Pagina Cerasus", text: "Cherry" },
] ]