Skip to content

Commit c0dc4b7

Browse files
authored
Merge pull request #2820 from ehuss/hash-files-default
Enable hash-files by default
2 parents 73a1652 + 6f3fac7 commit c0dc4b7

File tree

6 files changed

+48
-44
lines changed

6 files changed

+48
-44
lines changed

crates/mdbook-core/src/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ pub struct HtmlConfig {
482482
pub redirect: HashMap<String, String>,
483483
/// If this option is turned on, "cache bust" static files by adding
484484
/// hashes to their file names.
485+
///
486+
/// The default is `true`.
485487
pub hash_files: bool,
486488
}
487489

@@ -509,7 +511,7 @@ impl Default for HtmlConfig {
509511
edit_url_template: None,
510512
live_reload_endpoint: None,
511513
redirect: HashMap::new(),
512-
hash_files: false,
514+
hash_files: true,
513515
}
514516
}
515517
}

guide/src/format/configuration/renderers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ The following configuration options are available:
165165
For example, `css/chrome.css` may become `css/chrome-9b8f428e.css`.
166166
Chapter HTML files are not renamed.
167167
Static CSS and JS files can reference each other using `{{ resource "filename" }}` directives.
168-
Defaults to `false` (in a future release, this may change to `true`).
168+
Defaults to `true`.
169169

170170
[custom domain]: https://docs.github.com/en/github/working-with-github-pages/managing-a-custom-domain-for-your-github-pages-site
171171

tests/testsuite/book_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ impl BookTest {
124124
/// Returns the summary contents from `toc.js`.
125125
#[track_caller]
126126
pub fn toc_js_html(&self) -> String {
127-
let full_path = self.dir.join("book/toc.js");
128-
let actual = read_to_string(&full_path);
127+
let toc_path = glob_one(&self.dir, "book/toc*.js");
128+
let actual = read_to_string(&toc_path);
129129
let inner = actual
130130
.lines()
131131
.filter_map(|line| {

tests/testsuite/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ mod theme;
2525
mod toc;
2626

2727
mod prelude {
28-
pub use crate::book_test::{BookTest, read_to_string};
28+
pub use crate::book_test::{BookTest, glob_one, read_to_string};
2929
pub use snapbox::str;
3030
}

tests/testsuite/search.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use snapbox::file;
66
use std::path::Path;
77

88
fn read_book_index(root: &Path) -> serde_json::Value {
9-
let index = root.join("book/searchindex.js");
10-
let index = read_to_string(index);
9+
let index_path = glob_one(root, "book/searchindex*.js");
10+
let index = read_to_string(&index_path);
1111
let index =
1212
index.trim_start_matches("window.search = Object.assign(window.search, JSON.parse('");
1313
let index = index.trim_end_matches("'));");
@@ -87,7 +87,7 @@ fn reasonable_search_index() {
8787
#[test]
8888
fn search_index_hasnt_changed_accidentally() {
8989
BookTest::from_dir("search/reasonable_search_index").check_file(
90-
"book/searchindex.js",
90+
"book/searchindex*.js",
9191
file!["search/reasonable_search_index/expected_index.js"],
9292
);
9393
}

tests/testsuite/theme.rs

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,24 @@ This is a modified index.hbs!
4848
#[test]
4949
fn default_fonts() {
5050
BookTest::init(|_| {})
51-
.check_file_contains("book/index.html", "fonts/fonts.css")
51+
.check_file_contains("book/index.html", "fonts/fonts-[..].css")
5252
.check_file_list(
5353
"book/fonts",
5454
str![[r#"
5555
book/fonts/OPEN-SANS-LICENSE.txt
5656
book/fonts/SOURCE-CODE-PRO-LICENSE.txt
57-
book/fonts/fonts.css
58-
book/fonts/open-sans-v17-all-charsets-300.woff2
59-
book/fonts/open-sans-v17-all-charsets-300italic.woff2
60-
book/fonts/open-sans-v17-all-charsets-600.woff2
61-
book/fonts/open-sans-v17-all-charsets-600italic.woff2
62-
book/fonts/open-sans-v17-all-charsets-700.woff2
63-
book/fonts/open-sans-v17-all-charsets-700italic.woff2
64-
book/fonts/open-sans-v17-all-charsets-800.woff2
65-
book/fonts/open-sans-v17-all-charsets-800italic.woff2
66-
book/fonts/open-sans-v17-all-charsets-italic.woff2
67-
book/fonts/open-sans-v17-all-charsets-regular.woff2
68-
book/fonts/source-code-pro-v11-all-charsets-500.woff2
57+
book/fonts/fonts-[..].css
58+
book/fonts/open-sans-v17-all-charsets-300-[..].woff2
59+
book/fonts/open-sans-v17-all-charsets-300italic-[..].woff2
60+
book/fonts/open-sans-v17-all-charsets-600-[..].woff2
61+
book/fonts/open-sans-v17-all-charsets-600italic-[..].woff2
62+
book/fonts/open-sans-v17-all-charsets-700-[..].woff2
63+
book/fonts/open-sans-v17-all-charsets-700italic-[..].woff2
64+
book/fonts/open-sans-v17-all-charsets-800-[..].woff2
65+
book/fonts/open-sans-v17-all-charsets-800italic-[..].woff2
66+
book/fonts/open-sans-v17-all-charsets-italic-[..].woff2
67+
book/fonts/open-sans-v17-all-charsets-regular-[..].woff2
68+
book/fonts/source-code-pro-v11-all-charsets-500-[..].woff2
6969
"#]],
7070
);
7171
}
@@ -76,7 +76,7 @@ fn theme_fonts_copied() {
7676
BookTest::init(|bb| {
7777
bb.copy_theme(true);
7878
})
79-
.check_file_contains("book/index.html", "fonts/fonts.css")
79+
.check_file_contains("book/index.html", "fonts/fonts-[..].css")
8080
.check_file_list(
8181
"theme/fonts",
8282
str![[r#"
@@ -96,23 +96,25 @@ theme/fonts/open-sans-v17-all-charsets-regular.woff2
9696
theme/fonts/source-code-pro-v11-all-charsets-500.woff2
9797
"#]],
9898
)
99+
// Note that license files get hashed, which is not like the behavior when
100+
// the theme directory is empty. It kinda makes sense, but is weird.
99101
.check_file_list(
100102
"book/fonts",
101103
str![[r#"
102-
book/fonts/OPEN-SANS-LICENSE.txt
103-
book/fonts/SOURCE-CODE-PRO-LICENSE.txt
104-
book/fonts/fonts.css
105-
book/fonts/open-sans-v17-all-charsets-300.woff2
106-
book/fonts/open-sans-v17-all-charsets-300italic.woff2
107-
book/fonts/open-sans-v17-all-charsets-600.woff2
108-
book/fonts/open-sans-v17-all-charsets-600italic.woff2
109-
book/fonts/open-sans-v17-all-charsets-700.woff2
110-
book/fonts/open-sans-v17-all-charsets-700italic.woff2
111-
book/fonts/open-sans-v17-all-charsets-800.woff2
112-
book/fonts/open-sans-v17-all-charsets-800italic.woff2
113-
book/fonts/open-sans-v17-all-charsets-italic.woff2
114-
book/fonts/open-sans-v17-all-charsets-regular.woff2
115-
book/fonts/source-code-pro-v11-all-charsets-500.woff2
104+
book/fonts/OPEN-SANS-LICENSE-[..].txt
105+
book/fonts/SOURCE-CODE-PRO-LICENSE-[..].txt
106+
book/fonts/fonts-[..].css
107+
book/fonts/open-sans-v17-all-charsets-300-[..].woff2
108+
book/fonts/open-sans-v17-all-charsets-300italic-[..].woff2
109+
book/fonts/open-sans-v17-all-charsets-600-[..].woff2
110+
book/fonts/open-sans-v17-all-charsets-600italic-[..].woff2
111+
book/fonts/open-sans-v17-all-charsets-700-[..].woff2
112+
book/fonts/open-sans-v17-all-charsets-700italic-[..].woff2
113+
book/fonts/open-sans-v17-all-charsets-800-[..].woff2
114+
book/fonts/open-sans-v17-all-charsets-800italic-[..].woff2
115+
book/fonts/open-sans-v17-all-charsets-italic-[..].woff2
116+
book/fonts/open-sans-v17-all-charsets-regular-[..].woff2
117+
book/fonts/source-code-pro-v11-all-charsets-500-[..].woff2
116118
"#]],
117119
);
118120
}
@@ -121,20 +123,20 @@ book/fonts/source-code-pro-v11-all-charsets-500.woff2
121123
#[test]
122124
fn fonts_css() {
123125
BookTest::from_dir("theme/fonts_css")
124-
.check_file_contains("book/index.html", "fonts/fonts.css")
126+
.check_file_contains("book/index.html", "fonts/fonts-[..].css")
125127
.check_file(
126-
"book/fonts/fonts.css",
128+
"book/fonts/fonts-*.css",
127129
str![[r#"
128130
/*custom*/
129131
130132
"#]],
131133
)
132-
.check_file("book/fonts/myfont.woff", str![[""]])
134+
.check_file("book/fonts/myfont-*.woff", str![[""]])
133135
.check_file_list(
134136
"book/fonts",
135137
str![[r#"
136-
book/fonts/fonts.css
137-
book/fonts/myfont.woff
138+
book/fonts/fonts-[..].css
139+
book/fonts/myfont-[..].woff
138140
"#]],
139141
);
140142
}
@@ -167,12 +169,12 @@ fn custom_fonts_css() {
167169
168170
"#]]);
169171
})
170-
.check_file_contains("book/index.html", "fonts.css")
172+
.check_file_contains("book/index.html", "fonts-[..].css")
171173
.check_file_list(
172174
"book/fonts",
173175
str![[r#"
174-
book/fonts/fonts.css
175-
book/fonts/myfont.woff
176+
book/fonts/fonts-[..].css
177+
book/fonts/myfont-[..].woff
176178
"#]],
177179
);
178180
}

0 commit comments

Comments
 (0)