diff options
-rw-r--r-- | src/generate_html.rs | 13 | ||||
-rw-r--r-- | src/main.rs | 12 |
2 files changed, 19 insertions, 6 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs index 1e3acc7..f14d5f9 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -20,23 +20,24 @@ pub fn generate_html(document: &MarkdownDocument, page: &SourceFile, website: &W </html> \ ", page.name, website.name, - get_html_head(document).trim(), + get_html_head(document, page).trim(), document_to_html(document, page, website).trim() ) } -pub fn get_html_head(document: &MarkdownDocument) -> String { +pub fn get_html_head(document: &MarkdownDocument, page: &SourceFile) -> String { if let Some(Block::Fragment { language, content }) = document.blocks.first() { if language == "embed-html-head" { return content.to_string(); } } - String::from("\ -<link rel='stylesheet' type='text/css' media='screen' href='/static/screen.css'> -<link rel='stylesheet' type='text/css' media='print' href='/static/print.css'> -<script src='/static/render_math.js' defer></script> \ + let back = page.back_string(); + format!("\ +<link rel='stylesheet' type='text/css' media='screen' href='{back}static/screen.css'> +<link rel='stylesheet' type='text/css' media='print' href='{back}static/print.css'> +<script src='{back}static/render_math.js' defer></script> \ ") } diff --git a/src/main.rs b/src/main.rs index a1b38f6..0a62ec2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -247,6 +247,18 @@ pub struct SourceFile { pub headings: Vec<String>, } +impl SourceFile { + pub fn back_string(&self) -> String { + let mut back = String::new(); + for c in self.full_url.chars() { + if c == '/' { + back.push_str("../"); + } + } + return back; + } +} + pub struct StaticFile { pub full_url: String, // URL full path, with extension pub source_path: PathBuf, |