Added local fallback for clipboard.js

This commit is contained in:
Michal Budzynski 2017-05-31 21:51:19 +02:00
parent dfc24bec01
commit 3a809e4a1c
4 changed files with 23 additions and 1 deletions

View file

@ -171,6 +171,7 @@ impl Renderer for HtmlHandlebars {
book.write_file("highlight.css", &theme.highlight_css)?;
book.write_file("tomorrow-night.css", &theme.tomorrow_night_css)?;
book.write_file("highlight.js", &theme.highlight_js)?;
book.write_file("clipboard.min.js", &theme.clipboard_js)?;
book.write_file("_FontAwesome/css/font-awesome.css", theme::FONT_AWESOME)?;
book.write_file("_FontAwesome/fonts/fontawesome-webfont.eot", theme::FONT_AWESOME_EOT)?;
book.write_file("_FontAwesome/fonts/fontawesome-webfont.svg", theme::FONT_AWESOME_SVG)?;

7
src/theme/clipboard.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -24,8 +24,13 @@
<!-- MathJax -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<!-- Clipboard.js -->
<!-- Fetch Clipboard.js from CDN but have a local fallback -->
<script src="https://cdn.jsdelivr.net/clipboard.js/1.6.1/clipboard.min.js"></script>
<script>
if (typeof Clipboard == 'undefined') {
document.write(unescape("%3Cscript src='clipboard.min.js'%3E%3C/script%3E"));
}
</script>
<!-- Fetch JQuery from CDN but have a local fallback -->
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

View file

@ -11,6 +11,7 @@ pub static HIGHLIGHT_JS: &'static [u8] = include_bytes!("highlight.js");
pub static TOMORROW_NIGHT_CSS: &'static [u8] = include_bytes!("tomorrow-night.css");
pub static HIGHLIGHT_CSS: &'static [u8] = include_bytes!("highlight.css");
pub static JQUERY: &'static [u8] = include_bytes!("jquery-2.1.4.min.js");
pub static CLIPBOARD_JS: &'static [u8] = include_bytes!("clipboard.min.js");
pub static FONT_AWESOME: &'static [u8] = include_bytes!("_FontAwesome/css/font-awesome.min.css");
pub static FONT_AWESOME_EOT: &'static [u8] = include_bytes!("_FontAwesome/fonts/fontawesome-webfont.eot");
pub static FONT_AWESOME_SVG: &'static [u8] = include_bytes!("_FontAwesome/fonts/fontawesome-webfont.svg");
@ -36,6 +37,7 @@ pub struct Theme {
pub highlight_css: Vec<u8>,
pub tomorrow_night_css: Vec<u8>,
pub highlight_js: Vec<u8>,
pub clipboard_js: Vec<u8>,
pub jquery: Vec<u8>,
}
@ -51,6 +53,7 @@ impl Theme {
highlight_css: HIGHLIGHT_CSS.to_owned(),
tomorrow_night_css: TOMORROW_NIGHT_CSS.to_owned(),
highlight_js: HIGHLIGHT_JS.to_owned(),
clipboard_js: CLIPBOARD_JS.to_owned(),
jquery: JQUERY.to_owned(),
};
@ -91,6 +94,12 @@ impl Theme {
let _ = f.read_to_end(&mut theme.highlight_js);
}
// clipboard.js
if let Ok(mut f) = File::open(&src.join("clipboard.min.js")) {
theme.clipboard_js.clear();
let _ = f.read_to_end(&mut theme.clipboard_js);
}
// highlight.css
if let Ok(mut f) = File::open(&src.join("highlight.css")) {
theme.highlight_css.clear();