* Add index preprocessor README.md is a de facto index file in markdown-based documentation. Hence, we respect to README.md and convert it into index.html. * Fix warning for unused variables * Update tests for config * Match file stem case-insensitively for IndexPreprocessor * Add tests for IndexPreprocessor * Update book example to fit index preprocessor
40 lines
1 KiB
Rust
40 lines
1 KiB
Rust
//! Book preprocessing.
|
|
|
|
pub use self::links::LinkPreprocessor;
|
|
pub use self::index::IndexPreprocessor;
|
|
|
|
mod links;
|
|
mod index;
|
|
|
|
use book::Book;
|
|
use config::Config;
|
|
use errors::*;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
/// Extra information for a `Preprocessor` to give them more context when
|
|
/// processing a book.
|
|
pub struct PreprocessorContext {
|
|
/// The location of the book directory on disk.
|
|
pub root: PathBuf,
|
|
/// The book configuration (`book.toml`).
|
|
pub config: Config,
|
|
}
|
|
|
|
impl PreprocessorContext {
|
|
/// Create a new `PreprocessorContext`.
|
|
pub(crate) fn new(root: PathBuf, config: Config) -> Self {
|
|
PreprocessorContext { root, config }
|
|
}
|
|
}
|
|
|
|
/// An operation which is run immediately after loading a book into memory and
|
|
/// before it gets rendered.
|
|
pub trait Preprocessor {
|
|
/// Get the `Preprocessor`'s name.
|
|
fn name(&self) -> &str;
|
|
|
|
/// Run this `Preprocessor`, allowing it to update the book before it is
|
|
/// given to a renderer.
|
|
fn run(&self, ctx: &PreprocessorContext, book: &mut Book) -> Result<()>;
|
|
}
|