Expose API for building a book with a custom Summary.
This is useful for situations where you'd like to supplement or replace the existing Summary parsing with custom filesystem traversal code or other similar changes.
This commit is contained in:
parent
c068703028
commit
37808b7e08
|
@ -179,7 +179,7 @@ impl Chapter {
|
||||||
///
|
///
|
||||||
/// You need to pass in the book's source directory because all the links in
|
/// You need to pass in the book's source directory because all the links in
|
||||||
/// `SUMMARY.md` give the chapter locations relative to it.
|
/// `SUMMARY.md` give the chapter locations relative to it.
|
||||||
fn load_book_from_disk<P: AsRef<Path>>(summary: &Summary, src_dir: P) -> Result<Book> {
|
pub(crate) fn load_book_from_disk<P: AsRef<Path>>(summary: &Summary, src_dir: P) -> Result<Book> {
|
||||||
debug!("Loading the book from disk");
|
debug!("Loading the book from disk");
|
||||||
let src_dir = src_dir.as_ref();
|
let src_dir = src_dir.as_ref();
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,29 @@ impl MDBook {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Load a book from its root directory using a custom config and a custom summary.
|
||||||
|
pub fn load_with_config_and_summary<P: Into<PathBuf>>(
|
||||||
|
book_root: P,
|
||||||
|
config: Config,
|
||||||
|
summary: Summary
|
||||||
|
) -> Result<MDBook> {
|
||||||
|
let root = book_root.into();
|
||||||
|
|
||||||
|
let src_dir = root.join(&config.book.src);
|
||||||
|
let book = book::load_book_from_disk(&summary, &src_dir)?;
|
||||||
|
|
||||||
|
let renderers = determine_renderers(&config);
|
||||||
|
let preprocessors = determine_preprocessors(&config)?;
|
||||||
|
|
||||||
|
Ok(MDBook {
|
||||||
|
root,
|
||||||
|
config,
|
||||||
|
book,
|
||||||
|
renderers,
|
||||||
|
preprocessors,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a flat depth-first iterator over the elements of the book,
|
/// Returns a flat depth-first iterator over the elements of the book,
|
||||||
/// it returns an [BookItem enum](bookitem.html):
|
/// it returns an [BookItem enum](bookitem.html):
|
||||||
/// `(section: String, bookitem: &BookItem)`
|
/// `(section: String, bookitem: &BookItem)`
|
||||||
|
|
Loading…
Reference in New Issue