Skip to content

Commit 8a9ecd2

Browse files
committed
Fix, and test, the no-js toc sidebar with hashed resources
To make this work, I need to break the circular dependency and stop hashing toc.html itself.
1 parent ec157cd commit 8a9ecd2

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

src/renderer/html_handlebars/hbs_renderer.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,11 @@ impl Renderer for HtmlHandlebars {
392392
}
393393
}
394394

395-
debug!("Render toc");
395+
debug!("Render toc js");
396396
{
397397
let rendered_toc = handlebars.render("toc_js", &data)?;
398398
static_files.add_builtin("toc.js", rendered_toc.as_bytes());
399399
debug!("Creating toc.js ✓");
400-
data.insert("is_toc_html".to_owned(), json!(true));
401-
let rendered_toc = handlebars.render("toc_html", &data)?;
402-
static_files.add_builtin("toc.html", rendered_toc.as_bytes());
403-
debug!("Creating toc.html ✓");
404-
data.remove("is_toc_html");
405400
}
406401

407402
if html_config.hash_files {
@@ -415,6 +410,17 @@ impl Renderer for HtmlHandlebars {
415410

416411
handlebars.register_helper("resource", Box::new(resource_helper));
417412

413+
debug!("Render toc html");
414+
{
415+
data.insert("is_toc_html".to_owned(), json!(true));
416+
data.insert("path".to_owned(), json!("toc.html"));
417+
let rendered_toc = handlebars.render("toc_html", &data)?;
418+
utils::fs::write_file(destination, "toc.html", rendered_toc.as_bytes())?;
419+
debug!("Creating toc.html ✓");
420+
data.remove("path");
421+
data.remove("is_toc_html");
422+
}
423+
418424
utils::fs::write_file(
419425
destination,
420426
".nojekyll",

src/theme/index.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<!-- populated by js -->
112112
<mdbook-sidebar-scrollbox class="sidebar-scrollbox"></mdbook-sidebar-scrollbox>
113113
<noscript>
114-
<iframe class="sidebar-iframe-outer" src="{{ resource "toc.html" }}"></iframe>
114+
<iframe class="sidebar-iframe-outer" src="{{ path_to_root }}toc.html"></iframe>
115115
</noscript>
116116
<div id="sidebar-resize-handle" class="sidebar-resize-handle">
117117
<div class="sidebar-resize-indicator"></div>

src/theme/toc.html.hbs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121
{{> head}}
2222
<meta name="viewport" content="width=device-width, initial-scale=1">
2323
<meta name="theme-color" content="#ffffff">
24-
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
25-
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
26-
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
24+
<link rel="stylesheet" href="{{ resource "css/variables.css" }}">
25+
<link rel="stylesheet" href="{{ resource "css/general.css" }}">
26+
<link rel="stylesheet" href="{{ resource "css/chrome.css" }}">
2727
{{#if print_enable}}
28-
<link rel="stylesheet" href="{{ path_to_root }}css/print.css" media="print">
28+
<link rel="stylesheet" href="{{ resource "css/print.css" }}" media="print">
2929
{{/if}}
3030
<!-- Fonts -->
31-
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
31+
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
3232
{{#if copy_fonts}}
33-
<link rel="stylesheet" href="{{ path_to_root }}fonts/fonts.css">
33+
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">
3434
{{/if}}
3535
<!-- Custom theme stylesheets -->
3636
{{#each additional_css}}
37-
<link rel="stylesheet" href="{{ ../path_to_root }}{{ this }}">
37+
<link rel="stylesheet" href="{{ resource this }}">
3838
{{/each}}
3939
</head>
4040
<body class="sidebar-iframe-inner">

test_book/book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition = "2018"
99

1010
[output.html]
1111
mathjax-support = true
12+
hash-files = true
1213

1314
[output.html.playground]
1415
editable = true

0 commit comments

Comments
 (0)