Skip to content

Commit aaf0ff8

Browse files
committed
Call initSidebarItems in root module of crate
1 parent 75da570 commit aaf0ff8

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

src/librustdoc/html/render/mod.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1745,12 +1745,17 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
17451745
ty = it.type_(),
17461746
path = relpath
17471747
);
1748+
17481749
if parentlen == 0 {
1749-
// There is no sidebar-items.js beyond the crate root path
1750-
// FIXME maybe dynamic crate loading can be merged here
1750+
write!(
1751+
buffer,
1752+
"<script defer src=\"{}sidebar-items{}.js\"></script>",
1753+
relpath, cx.shared.resource_suffix
1754+
);
17511755
} else {
1752-
write!(buffer, "<script defer src=\"{path}sidebar-items.js\"></script>", path = relpath);
1756+
write!(buffer, "<script defer src=\"{}sidebar-items.js\"></script>", relpath);
17531757
}
1758+
17541759
// Closes sidebar-elems div.
17551760
buffer.write_str("</div>");
17561761
}

src/librustdoc/html/render/write_shared.rs

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ pub(super) fn write_shared(
225225
)?;
226226
write_minify("search.js", static_files::SEARCH_JS)?;
227227
write_minify("settings.js", static_files::SETTINGS_JS)?;
228+
write_minify("sidebar-items.js", static_files::sidebar::ITEMS)?;
229+
228230
if cx.shared.include_sources {
229231
write_minify("source-script.js", static_files::sidebar::SOURCE_SCRIPT)?;
230232
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
initSidebarItems({});

src/librustdoc/html/static_files.rs

+3
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,7 @@ crate mod source_code_pro {
130130
crate mod sidebar {
131131
/// File script to handle sidebar.
132132
crate static SOURCE_SCRIPT: &str = include_str!("static/source-script.js");
133+
134+
/// Top Level sidebar items script which will load a sidebar without items.
135+
crate static ITEMS: &str = include_str!("static/sidebar-items.js");
133136
}

0 commit comments

Comments
 (0)