diff options
-rw-r--r-- | src/generate_html.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs index 383015a..47dc5bf 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -94,6 +94,7 @@ pub fn get_table_of_contents(page: &Page) -> String { pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Website) -> String { + let from = &page.name; let mut html = String::new(); macro_rules! line_to_html { @@ -152,19 +153,22 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs Block::Note(lines) => wrap!("aside", for line in lines { tag!("p", line) }), Block::Embed { label, path } => match path.rsplit_once('.') { Some((_, extension)) => { - let path = match path.strip_prefix('/') { - Some(stripped) => format!("{root}{stripped}"), - None => path.to_string(), - }; + let mut path = path.to_string(); + if !path.contains("://") { + match website.has_static(page, &path) { + Some(resolved) => path = resolved, + None => warn!("Page {from:?} embeds nonexistent static file {path:?}"), + } + } let label = sanitize_text(label); match extension.to_lowercase().as_str() { "jpg"|"jpeg"|"png"|"webp"|"gif"|"tiff" => html!( "<figure><a href='{path}'><img src='{path}' alt='{label}' title='{label}' /></a></figure>"), "mp3"|"wav"|"m4a" => html!("<audio controls src='{path}'>{label}</audio>"), - ext @ _ => warn!("Unrecognised extension for embedded file {path:?} with extension {ext:?} in page {:?}", page.name), + ext @ _ => warn!("Unrecognised extension for embedded file {path:?} with extension {ext:?} in page {from:?}"), } } - _ => warn!("Cannot embed file {path:?} with no file extension in page {:?}", page.name), + _ => warn!("Cannot embed file {path:?} with no file extension in page {from:?}"), } Block::Fragment { language, content } => { match language.as_str() { @@ -184,7 +188,7 @@ pub fn document_to_html(document: &MarkdownDocument, page: &Page, website: &Webs "gallery" => wrap!("div", "class='gallery'", for line in content.lines() { let file = line.trim(); if !website.has_image(file) { - warn!("Gallery on page {:?} references nonexistent image {file:?}", page.name); + warn!("Gallery on page {from:?} references nonexistent image {file:?}"); continue; } let large = format!("{root}images/large/{file}"); @@ -297,7 +301,7 @@ fn line_to_html(line: &Line, page: &Page, website: &Website) -> String { if is_internal { // Check that the linked static file exists. match website.has_static(page, &path) { - Some(resolved_path) => path = resolved_path, + Some(resolved) => path = resolved, None => warn!("Page {from:?} contains link to nonexistent static file {path:?}"), } // Take the file name as the label if the link is unlabeled. |