Fasten even more theme switch
This commit is contained in:
parent
5f93159e9d
commit
5b8504401c
3 changed files with 15 additions and 12 deletions
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use externalfiles::ExternalHtml;
|
use externalfiles::ExternalHtml;
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ pub struct Page<'a> {
|
||||||
|
|
||||||
pub fn render<T: fmt::Display, S: fmt::Display>(
|
pub fn render<T: fmt::Display, S: fmt::Display>(
|
||||||
dst: &mut io::Write, layout: &Layout, page: &Page, sidebar: &S, t: &T,
|
dst: &mut io::Write, layout: &Layout, page: &Page, sidebar: &S, t: &T,
|
||||||
css_file_extension: bool)
|
css_file_extension: bool, themes: &[PathBuf])
|
||||||
-> io::Result<()>
|
-> io::Result<()>
|
||||||
{
|
{
|
||||||
write!(dst,
|
write!(dst,
|
||||||
|
@ -48,7 +49,9 @@ r##"<!DOCTYPE html>
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="{root_path}normalize.css">
|
<link rel="stylesheet" type="text/css" href="{root_path}normalize.css">
|
||||||
<link rel="stylesheet" type="text/css" href="{root_path}rustdoc.css" id="mainThemeStyle">
|
<link rel="stylesheet" type="text/css" href="{root_path}rustdoc.css" id="mainThemeStyle">
|
||||||
<link rel="stylesheet" type="text/css" href="" id="themeStyle">
|
{themes}
|
||||||
|
<link rel="stylesheet" type="text/css" href="{root_path}dark.css">
|
||||||
|
<link rel="stylesheet" type="text/css" href="{root_path}main.css" id="themeStyle">
|
||||||
<script src="{root_path}storage.js"></script>
|
<script src="{root_path}storage.js"></script>
|
||||||
{css_extension}
|
{css_extension}
|
||||||
|
|
||||||
|
@ -182,6 +185,12 @@ r##"<!DOCTYPE html>
|
||||||
after_content = layout.external_html.after_content,
|
after_content = layout.external_html.after_content,
|
||||||
sidebar = *sidebar,
|
sidebar = *sidebar,
|
||||||
krate = layout.krate,
|
krate = layout.krate,
|
||||||
|
themes = themes.iter()
|
||||||
|
.filter_map(|t| t.file_stem())
|
||||||
|
.filter_map(|t| t.to_str())
|
||||||
|
.map(|t| format!(r#"<link rel="stylesheet" type="text/css" href="{}{}">"#,
|
||||||
|
page.root_path, t))
|
||||||
|
.collect::<String>(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1224,7 +1224,8 @@ impl<'a> SourceCollector<'a> {
|
||||||
};
|
};
|
||||||
layout::render(&mut w, &self.scx.layout,
|
layout::render(&mut w, &self.scx.layout,
|
||||||
&page, &(""), &Source(contents),
|
&page, &(""), &Source(contents),
|
||||||
self.scx.css_file_extension.is_some())?;
|
self.scx.css_file_extension.is_some(),
|
||||||
|
&self.scx.themes)?;
|
||||||
w.flush()?;
|
w.flush()?;
|
||||||
self.scx.local_sources.insert(p.clone(), href);
|
self.scx.local_sources.insert(p.clone(), href);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1588,7 +1589,8 @@ impl Context {
|
||||||
layout::render(writer, &self.shared.layout, &page,
|
layout::render(writer, &self.shared.layout, &page,
|
||||||
&Sidebar{ cx: self, item: it },
|
&Sidebar{ cx: self, item: it },
|
||||||
&Item{ cx: self, item: it },
|
&Item{ cx: self, item: it },
|
||||||
self.shared.css_file_extension.is_some())?;
|
self.shared.css_file_extension.is_some(),
|
||||||
|
&self.shared.themes)?;
|
||||||
} else {
|
} else {
|
||||||
let mut url = self.root_path();
|
let mut url = self.root_path();
|
||||||
if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
|
if let Some(&(ref names, ty)) = cache().paths.get(&it.def_id) {
|
||||||
|
|
|
@ -31,14 +31,6 @@ function getCurrentValue(name) {
|
||||||
function switchTheme(styleElem, mainStyleElem, newTheme) {
|
function switchTheme(styleElem, mainStyleElem, newTheme) {
|
||||||
styleElem.href = mainStyleElem.href.replace("rustdoc.css", newTheme + ".css");
|
styleElem.href = mainStyleElem.href.replace("rustdoc.css", newTheme + ".css");
|
||||||
updateLocalStorage('theme', newTheme);
|
updateLocalStorage('theme', newTheme);
|
||||||
/*var elem = document.getElementsByTagName('body')[0];
|
|
||||||
if (elem) {
|
|
||||||
updateLocalStorage('background', getComputedStyle(elem)['background-color']);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*var elem = document.getElementsByTagName('body')[0];
|
|
||||||
if (elem) {
|
|
||||||
var value =
|
|
||||||
}*/
|
|
||||||
switchTheme(currentTheme, mainTheme, getCurrentValue('theme') || 'main');
|
switchTheme(currentTheme, mainTheme, getCurrentValue('theme') || 'main');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue