Change template to use new CSS
This commit is contained in:
parent
3119a7e4bf
commit
ac38f05bb6
|
@ -127,8 +127,20 @@ impl BookBuilder {
|
||||||
let mut index = File::create(themedir.join("index.hbs"))?;
|
let mut index = File::create(themedir.join("index.hbs"))?;
|
||||||
index.write_all(theme::INDEX)?;
|
index.write_all(theme::INDEX)?;
|
||||||
|
|
||||||
let mut css = File::create(themedir.join("book.css"))?;
|
let cssdir = themedir.join("css");
|
||||||
css.write_all(theme::CSS)?;
|
fs::create_dir(&cssdir)?;
|
||||||
|
|
||||||
|
let mut general_css = File::create(cssdir.join("general.css"))?;
|
||||||
|
general_css.write_all(theme::GENERAL_CSS)?;
|
||||||
|
|
||||||
|
let mut chrome_css = File::create(cssdir.join("chrome.css"))?;
|
||||||
|
chrome_css.write_all(theme::CHROME_CSS)?;
|
||||||
|
|
||||||
|
let mut print_css = File::create(cssdir.join("print.css"))?;
|
||||||
|
print_css.write_all(theme::PRINT_CSS)?;
|
||||||
|
|
||||||
|
let mut variables_css = File::create(cssdir.join("variables.css"))?;
|
||||||
|
variables_css.write_all(theme::VARIABLES_CSS)?;
|
||||||
|
|
||||||
let mut favicon = File::create(themedir.join("favicon.png"))?;
|
let mut favicon = File::create(themedir.join("favicon.png"))?;
|
||||||
favicon.write_all(theme::FAVICON)?;
|
favicon.write_all(theme::FAVICON)?;
|
||||||
|
|
|
@ -139,7 +139,10 @@ impl HtmlHandlebars {
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
write_file(destination, "book.js", &theme.js)?;
|
write_file(destination, "book.js", &theme.js)?;
|
||||||
write_file(destination, "book.css", &theme.css)?;
|
write_file(destination, "css/general.css", &theme.general_css)?;
|
||||||
|
write_file(destination, "css/chrome.css", &theme.chrome_css)?;
|
||||||
|
write_file(destination, "css/print.css", &theme.print_css)?;
|
||||||
|
write_file(destination, "css/variables.css", &theme.variables_css)?;
|
||||||
write_file(destination, "favicon.png", &theme.favicon)?;
|
write_file(destination, "favicon.png", &theme.favicon)?;
|
||||||
write_file(destination, "highlight.css", &theme.highlight_css)?;
|
write_file(destination, "highlight.css", &theme.highlight_css)?;
|
||||||
write_file(destination, "tomorrow-night.css", &theme.tomorrow_night_css)?;
|
write_file(destination, "tomorrow-night.css", &theme.tomorrow_night_css)?;
|
||||||
|
|
|
@ -9,29 +9,31 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta name="theme-color" content="#ffffff" />
|
<meta name="theme-color" content="#ffffff" />
|
||||||
|
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}book.css">
|
<link rel="shortcut icon" href="{{ favicon }}">
|
||||||
|
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
|
||||||
|
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
|
||||||
|
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
|
||||||
|
<link rel="stylesheet" href="{{ path_to_root }}css/print.css" media="print">
|
||||||
|
|
||||||
|
<!-- Fonts -->
|
||||||
|
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
|
||||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">
|
||||||
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">
|
<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500" rel="stylesheet" type="text/css">
|
||||||
|
|
||||||
<link rel="shortcut icon" href="{{ favicon }}">
|
<!-- Highlight.js Stylesheets -->
|
||||||
|
|
||||||
<!-- Font Awesome -->
|
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}highlight.css">
|
<link rel="stylesheet" href="{{ path_to_root }}highlight.css">
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}tomorrow-night.css">
|
<link rel="stylesheet" href="{{ path_to_root }}tomorrow-night.css">
|
||||||
<link rel="stylesheet" href="{{ path_to_root }}ayu-highlight.css">
|
<link rel="stylesheet" href="{{ path_to_root }}ayu-highlight.css">
|
||||||
|
|
||||||
<!-- Custom theme stylesheets -->
|
<!-- Custom theme stylesheets -->
|
||||||
{{#each additional_css}}
|
{{#each additional_css}}
|
||||||
<link rel="stylesheet" href="{{this}}">
|
<link rel="stylesheet" href="{{ this }}">
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
||||||
{{#if mathjax_support}}
|
{{#if mathjax_support}}
|
||||||
<!-- MathJax -->
|
<!-- MathJax -->
|
||||||
<script async type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
<script async type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body class="light">
|
<body class="light">
|
||||||
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
<!-- Work around some values being stored in localStorage wrapped in quotes -->
|
||||||
|
|
|
@ -13,7 +13,10 @@ use errors::*;
|
||||||
|
|
||||||
pub static INDEX: &'static [u8] = include_bytes!("index.hbs");
|
pub static INDEX: &'static [u8] = include_bytes!("index.hbs");
|
||||||
pub static HEADER: &'static [u8] = include_bytes!("header.hbs");
|
pub static HEADER: &'static [u8] = include_bytes!("header.hbs");
|
||||||
pub static CSS: &'static [u8] = include_bytes!("book.css");
|
pub static CHROME_CSS: &'static [u8] = include_bytes!("css/chrome.css");
|
||||||
|
pub static GENERAL_CSS: &'static [u8] = include_bytes!("css/general.css");
|
||||||
|
pub static PRINT_CSS: &'static [u8] = include_bytes!("css/print.css");
|
||||||
|
pub static VARIABLES_CSS: &'static [u8] = include_bytes!("css/variables.css");
|
||||||
pub static FAVICON: &'static [u8] = include_bytes!("favicon.png");
|
pub static FAVICON: &'static [u8] = include_bytes!("favicon.png");
|
||||||
pub static JS: &'static [u8] = include_bytes!("book.js");
|
pub static JS: &'static [u8] = include_bytes!("book.js");
|
||||||
pub static HIGHLIGHT_JS: &'static [u8] = include_bytes!("highlight.js");
|
pub static HIGHLIGHT_JS: &'static [u8] = include_bytes!("highlight.js");
|
||||||
|
@ -44,7 +47,10 @@ pub static FONT_AWESOME_OTF: &'static [u8] = include_bytes!("FontAwesome/fonts/F
|
||||||
pub struct Theme {
|
pub struct Theme {
|
||||||
pub index: Vec<u8>,
|
pub index: Vec<u8>,
|
||||||
pub header: Vec<u8>,
|
pub header: Vec<u8>,
|
||||||
pub css: Vec<u8>,
|
pub chrome_css: Vec<u8>,
|
||||||
|
pub general_css: Vec<u8>,
|
||||||
|
pub print_css: Vec<u8>,
|
||||||
|
pub variables_css: Vec<u8>,
|
||||||
pub favicon: Vec<u8>,
|
pub favicon: Vec<u8>,
|
||||||
pub js: Vec<u8>,
|
pub js: Vec<u8>,
|
||||||
pub highlight_css: Vec<u8>,
|
pub highlight_css: Vec<u8>,
|
||||||
|
@ -72,7 +78,13 @@ impl Theme {
|
||||||
(theme_dir.join("index.hbs"), &mut theme.index),
|
(theme_dir.join("index.hbs"), &mut theme.index),
|
||||||
(theme_dir.join("header.hbs"), &mut theme.header),
|
(theme_dir.join("header.hbs"), &mut theme.header),
|
||||||
(theme_dir.join("book.js"), &mut theme.js),
|
(theme_dir.join("book.js"), &mut theme.js),
|
||||||
(theme_dir.join("book.css"), &mut theme.css),
|
(theme_dir.join("css/chrome.css"), &mut theme.chrome_css),
|
||||||
|
(theme_dir.join("css/general.css"), &mut theme.general_css),
|
||||||
|
(theme_dir.join("css/print.css"), &mut theme.print_css),
|
||||||
|
(
|
||||||
|
theme_dir.join("css/variables.css"),
|
||||||
|
&mut theme.variables_css,
|
||||||
|
),
|
||||||
(theme_dir.join("favicon.png"), &mut theme.favicon),
|
(theme_dir.join("favicon.png"), &mut theme.favicon),
|
||||||
(theme_dir.join("highlight.js"), &mut theme.highlight_js),
|
(theme_dir.join("highlight.js"), &mut theme.highlight_js),
|
||||||
(theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js),
|
(theme_dir.join("clipboard.min.js"), &mut theme.clipboard_js),
|
||||||
|
@ -107,7 +119,10 @@ impl Default for Theme {
|
||||||
Theme {
|
Theme {
|
||||||
index: INDEX.to_owned(),
|
index: INDEX.to_owned(),
|
||||||
header: HEADER.to_owned(),
|
header: HEADER.to_owned(),
|
||||||
css: CSS.to_owned(),
|
chrome_css: CHROME_CSS.to_owned(),
|
||||||
|
general_css: GENERAL_CSS.to_owned(),
|
||||||
|
print_css: PRINT_CSS.to_owned(),
|
||||||
|
variables_css: VARIABLES_CSS.to_owned(),
|
||||||
favicon: FAVICON.to_owned(),
|
favicon: FAVICON.to_owned(),
|
||||||
js: JS.to_owned(),
|
js: JS.to_owned(),
|
||||||
highlight_css: HIGHLIGHT_CSS.to_owned(),
|
highlight_css: HIGHLIGHT_CSS.to_owned(),
|
||||||
|
@ -138,6 +153,7 @@ fn load_file_contents<P: AsRef<Path>>(filename: P, dest: &mut Vec<u8>) -> Result
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tempfile::Builder as TempFileBuilder;
|
use tempfile::Builder as TempFileBuilder;
|
||||||
|
|
||||||
|
@ -154,21 +170,28 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn theme_dir_overrides_defaults() {
|
fn theme_dir_overrides_defaults() {
|
||||||
// Get all the non-Rust files in the theme directory
|
let files = [
|
||||||
let special_files = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
"index.hbs",
|
||||||
.join("src/theme")
|
"header.hbs",
|
||||||
.read_dir()
|
"favicon.png",
|
||||||
.unwrap()
|
"css/chrome.css",
|
||||||
.filter_map(|f| f.ok())
|
"css/general.css",
|
||||||
.map(|f| f.path())
|
"css/print.css",
|
||||||
.filter(|p| p.is_file() && !p.ends_with(".rs"));
|
"css/variables.css",
|
||||||
|
"book.js",
|
||||||
|
"highlight.js",
|
||||||
|
"tomorrow-night.css",
|
||||||
|
"highlight.css",
|
||||||
|
"ayu-highlight.css",
|
||||||
|
"clipboard.min.js",
|
||||||
|
];
|
||||||
|
|
||||||
let temp = TempFileBuilder::new().prefix("mdbook").tempdir().unwrap();
|
let temp = TempFileBuilder::new().prefix("mdbook-").tempdir().unwrap();
|
||||||
|
fs::create_dir(temp.path().join("css")).unwrap();
|
||||||
|
|
||||||
// "touch" all of the special files so we have empty copies
|
// "touch" all of the special files so we have empty copies
|
||||||
for special_file in special_files {
|
for file in &files {
|
||||||
let filename = temp.path().join(special_file.file_name().unwrap());
|
File::create(&temp.path().join(file)).unwrap();
|
||||||
let _ = File::create(&filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let got = Theme::new(temp.path());
|
let got = Theme::new(temp.path());
|
||||||
|
@ -176,7 +199,10 @@ mod tests {
|
||||||
let empty = Theme {
|
let empty = Theme {
|
||||||
index: Vec::new(),
|
index: Vec::new(),
|
||||||
header: Vec::new(),
|
header: Vec::new(),
|
||||||
css: Vec::new(),
|
chrome_css: Vec::new(),
|
||||||
|
general_css: Vec::new(),
|
||||||
|
print_css: Vec::new(),
|
||||||
|
variables_css: Vec::new(),
|
||||||
favicon: Vec::new(),
|
favicon: Vec::new(),
|
||||||
js: Vec::new(),
|
js: Vec::new(),
|
||||||
highlight_css: Vec::new(),
|
highlight_css: Vec::new(),
|
||||||
|
|
Loading…
Reference in New Issue