toolkit for mdBook [mirror of my GitHub repo] docs.tonywu.dev/mdbookkit/
permalinks rust-analyzer mdbook
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: support previous config sections

Tony Wu b1fc2347 8063d291

+29 -10
+1 -2
crates/mdbook-permalinks/src/main.rs
··· 169 169 fn new(book: &PreprocessorContext) -> Result<Result<Self>> { 170 170 let config = book 171 171 .config 172 - .preprocessor(PREPROCESSOR_NAME) 173 - .context("failed to read preprocessor config from book.toml")?; 172 + .preprocessor(&[PREPROCESSOR_NAME, "mdbook-link-forever"])?; 174 173 175 174 let vcs = match VersionControl::try_from_git(&config, &book.config) { 176 175 Ok(Ok(vcs)) => vcs,
+3 -1
crates/mdbook-rustdoc-links/src/main.rs
··· 217 217 } 218 218 219 219 fn config(ctx: &PreprocessorContext) -> Result2<Config> { 220 - let mut config = ctx.config.preprocessor::<Config>(PREPROCESSOR_NAME)?; 220 + let mut config = ctx 221 + .config 222 + .preprocessor::<Config>(&[PREPROCESSOR_NAME, "mdbook-rustdoc-link"])?; 221 223 222 224 if let Some(path) = config.manifest_dir { 223 225 config.manifest_dir = Some(ctx.root.join(path))
+23 -5
crates/mdbookkit/src/book.rs
··· 39 39 } 40 40 41 41 pub trait BookConfigHelper { 42 - fn preprocessor<'de, T>(&self, name: &str) -> Result<T> 42 + fn preprocessor<'de, T>(&self, names: &[&str]) -> Result<T> 43 43 where 44 44 T: Deserialize<'de> + Default; 45 45 ··· 47 47 } 48 48 49 49 impl BookConfigHelper for MDBookConfig { 50 - fn preprocessor<'de, T>(&self, name: &str) -> Result<T> 50 + fn preprocessor<'de, T>(&self, names: &[&str]) -> Result<T> 51 51 where 52 52 T: Deserialize<'de> + Default, 53 53 { 54 - let name = name.strip_prefix("mdbook-").unwrap_or(name); 55 - let name = format!("preprocessor.{name}"); 56 - Ok(self.get::<T>(&name)?.unwrap_or_default()) 54 + fn format_name(name: &str) -> String { 55 + let name = name.strip_prefix("mdbook-").unwrap_or(name); 56 + format!("preprocessor.{name}") 57 + } 58 + 59 + for (idx, name) in names.iter().enumerate() { 60 + let name = format_name(name); 61 + if let Some(value) = (self.get::<T>(&name)) 62 + .with_context(|| format!("error while reading [{name}] in book.toml"))? 63 + { 64 + if idx != 0 { 65 + let recommended = format_name(names[0]); 66 + log::warn!( 67 + "The book.toml section [{name}] is deprecated. Use [{recommended}] instead." 68 + ); 69 + } 70 + return Ok(value); 71 + } 72 + } 73 + 74 + Ok(Default::default()) 57 75 } 58 76 59 77 fn markdown_options(&self) -> MarkdownOptions {
+2 -2
crates/mdbookkit/src/error.rs
··· 36 36 log::Level::Error => Err(anyhow!("preprocessor has errors")), 37 37 log::Level::Warn => match self { 38 38 Self::AlwaysFail => { 39 - anyhow!("treating warnings as errors because fail-on-unresolved is \"always\"") 39 + anyhow!("treating warnings as errors because the `fail-on-warnings` option is set to \"always\"") 40 40 .context("preprocessor has errors") 41 41 .pipe(Err) 42 42 } ··· 44 44 let Some(ci) = Self::warning_as_error() else { 45 45 return Ok(()); 46 46 }; 47 - anyhow!("treating warnings as errors because fail-on-unresolved is \"ci\" and CI={ci}") 47 + anyhow!("treating warnings as errors because the `fail-on-warnings` option is set to \"ci\" and CI={ci}") 48 48 .context("preprocessor has errors") 49 49 .pipe(Err) 50 50 }