@@ -7,11 +7,11 @@ use crate::theme::{self, playpen_editor, Theme};
7
7
use crate :: utils;
8
8
9
9
use std:: borrow:: Cow ;
10
+ use std:: collections:: hash_map:: DefaultHasher ;
10
11
use std:: collections:: BTreeMap ;
11
12
use std:: collections:: HashMap ;
12
- use std:: collections:: hash_map:: DefaultHasher ;
13
- use std:: hash:: Hasher ;
14
13
use std:: fs:: { self , OpenOptions } ;
14
+ use std:: hash:: Hasher ;
15
15
use std:: io:: Write ;
16
16
use std:: path:: { Path , PathBuf } ;
17
17
@@ -32,15 +32,19 @@ impl HtmlHandlebars {
32
32
HtmlHandlebars
33
33
}
34
34
35
- fn build_service_worker ( & self , build_dir : & Path , chapter_files : & Vec < ChapterFile > ) -> Result < ( ) > {
35
+ fn build_service_worker (
36
+ & self ,
37
+ build_dir : & Path ,
38
+ chapter_files : & Vec < ChapterFile > ,
39
+ ) -> Result < ( ) > {
36
40
let path = build_dir. join ( "sw.js" ) ;
37
41
let mut file = OpenOptions :: new ( ) . append ( true ) . open ( path) ?;
38
42
let mut content = String :: from ( "\n const chapters = [\n " ) ;
39
43
40
- for chapter_file in chapter_files {
44
+ for chapter_file in chapter_files {
41
45
content. push_str ( " { url: " ) ;
42
46
43
- // Rewrite "/" to point to the current directory
47
+ // Rewrite "/" to point to the current directory
44
48
// https://rust-lang-nursery.github.io/ => https://rust-lang-nursery.github.io/mdBook/
45
49
// location.href is https://rust-lang-nursery.github.io/mdBook/sw.js
46
50
// so we remove the sw.js from the end to get the correct path
@@ -52,17 +56,17 @@ impl HtmlHandlebars {
52
56
content. push_str ( "'" ) ;
53
57
}
54
58
55
- content. push_str ( ", revision: '" ) ;
59
+ content. push_str ( ", revision: '" ) ;
56
60
content. push_str ( & chapter_file. revision . to_string ( ) ) ;
57
61
content. push_str ( "' },\n " ) ;
58
62
}
59
63
60
- content. push_str ( "];\n " ) ;
64
+ content. push_str ( "];\n " ) ;
61
65
content. push_str ( "\n workbox.precaching.precacheAndRoute(chapters);\n " ) ;
62
66
63
- file. write ( content. as_bytes ( ) ) ?;
67
+ file. write ( content. as_bytes ( ) ) ?;
64
68
65
- Ok ( ( ) )
69
+ Ok ( ( ) )
66
70
}
67
71
68
72
fn render_item (
@@ -90,9 +94,9 @@ impl HtmlHandlebars {
90
94
. to_str ( )
91
95
. chain_err ( || "Could not convert path to str" ) ?;
92
96
let filepath = Path :: new ( & ch. path ) . with_extension ( "html" ) ;
93
- let filepath_str = filepath. to_str ( ) . ok_or_else ( || {
94
- Error :: from ( format ! ( "Bad file name: {}" , filepath . display ( ) ) )
95
- } ) ?;
97
+ let filepath_str = filepath
98
+ . to_str ( )
99
+ . ok_or_else ( || Error :: from ( format ! ( "Bad file name: {}" , filepath . display ( ) ) ) ) ?;
96
100
97
101
// "print.html" is used for the print page.
98
102
if ch. path == Path :: new ( "print.md" ) {
0 commit comments