Skip to content

Commit

Permalink
Prepend site url to image links as mdbook does not for some reason
Browse files Browse the repository at this point in the history
  • Loading branch information
fenjalien committed Apr 14, 2024
1 parent f44aba7 commit 5b08576
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions example/src/f/a.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ This is a nested example



![](/a/mdbook-typst-doc/525af.svg)
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct Config<'a> {
pub root: Option<String>,
pub src: String,
pub cache: String,
pub url: String,
pub handlebars: Handlebars<'a>,
}

Expand All @@ -83,6 +84,7 @@ impl<'a> Default for Config<'a> {
root: None,
src: String::new(),
cache: String::new(),
url: String::new(),
handlebars: hb,
}
}
Expand Down Expand Up @@ -120,6 +122,10 @@ impl<'a> Config<'a> {
..Default::default()
};

if let Some(html_config) = config.html_config() {
cfg.url = html_config.site_url.unwrap_or_default() + &cfg.src;
}

if !Path::new(&cfg.cache).exists() {
fs::create_dir(&cfg.cache)?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl TypstPreprocessor {

sender.send(child).unwrap();
}
data.insert("image", format!("![]({}/{name})", &config.cache));
data.insert("image", format!("![]({}/{name})", &config.url));
}
config
.handlebars
Expand Down

0 comments on commit 5b08576

Please sign in to comment.