Skip to content

Commit ae1a8c3

Browse files
committed
Don't serialize the default for book.src
This changes the serialization so that `book.src` is not serialized if it is the default. This removes the somewhat pointless `src = "src"` which shows up in the default `mdbook init` output. Deserialization should still default to `"src"`.
1 parent 0043043 commit ae1a8c3

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

crates/mdbook-core/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ pub struct BookConfig {
297297
/// An optional description for the book.
298298
pub description: Option<String>,
299299
/// Location of the book source relative to the book's root directory.
300+
#[serde(skip_serializing_if = "is_default_src")]
300301
pub src: PathBuf,
301302
/// The main language of the book.
302303
pub language: Option<String>,
@@ -305,6 +306,11 @@ pub struct BookConfig {
305306
pub text_direction: Option<TextDirection>,
306307
}
307308

309+
/// Helper for serde serialization.
310+
fn is_default_src(src: &PathBuf) -> bool {
311+
src == Path::new("src")
312+
}
313+
308314
impl Default for BookConfig {
309315
fn default() -> BookConfig {
310316
BookConfig {

tests/testsuite/init.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ All done, no errors...
2828
str![[r#"
2929
[book]
3030
authors = []
31-
src = "src"
3231
language = "en"
3332
3433
"#]],
@@ -94,7 +93,6 @@ All done, no errors...
9493
str![[r#"
9594
[book]
9695
authors = []
97-
src = "src"
9896
language = "en"
9997
10098
"#]],
@@ -128,7 +126,6 @@ All done, no errors...
128126
[book]
129127
title = "Example title"
130128
authors = []
131-
src = "src"
132129
language = "en"
133130
134131
"#]],

tests/testsuite/renderer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ fn backends_receive_render_context_via_stdin() {
188188
"authors": [],
189189
"description": null,
190190
"language": "en",
191-
"src": "src",
192191
"text-direction": null,
193192
"title": null
194193
},

0 commit comments

Comments
 (0)