Fix {{#include}} directives for default language
This commit is contained in:
parent
98c3a04022
commit
8d1c0869b7
@ -21,6 +21,7 @@
|
||||
- [Syntax highlighting](format/theme/syntax-highlighting.md)
|
||||
- [Editor](format/theme/editor.md)
|
||||
- [MathJax Support](format/mathjax.md)
|
||||
- [Localization](format/localization.md)
|
||||
- [mdBook-specific features](format/mdbook.md)
|
||||
- [Continuous Integration](continuous-integration.md)
|
||||
- [For Developers](for_developers/README.md)
|
||||
|
1
guide/src/en/format/configuration/localization.md
Normal file
1
guide/src/en/format/configuration/localization.md
Normal file
@ -0,0 +1 @@
|
||||
# Localization
|
@ -215,26 +215,35 @@ impl MDBook {
|
||||
|
||||
/// Run the entire build process for a particular [`Renderer`].
|
||||
pub fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()> {
|
||||
let preprocessed_books = match &self.book {
|
||||
LoadedBook::Localized(ref books) => {
|
||||
let mut new_books = HashMap::new();
|
||||
|
||||
for (language_ident, book) in books.0.iter() {
|
||||
let preprocess_ctx = PreprocessorContext::new(
|
||||
self.root.clone(),
|
||||
Some(language_ident.clone()),
|
||||
self.build_opts.clone(),
|
||||
self.config.clone(),
|
||||
renderer.name().to_string(),
|
||||
);
|
||||
|
||||
let preprocessed_books = match &self.book {
|
||||
LoadedBook::Localized(ref books) => {
|
||||
let mut new_books = HashMap::new();
|
||||
|
||||
for (ident, book) in books.0.iter() {
|
||||
let preprocessed_book =
|
||||
self.preprocess(&preprocess_ctx, renderer, book.clone())?;
|
||||
new_books.insert(ident.clone(), preprocessed_book);
|
||||
new_books.insert(language_ident.clone(), preprocessed_book);
|
||||
}
|
||||
|
||||
LoadedBook::Localized(LocalizedBooks(new_books))
|
||||
}
|
||||
LoadedBook::Single(ref book) => {
|
||||
let preprocess_ctx = PreprocessorContext::new(
|
||||
self.root.clone(),
|
||||
None,
|
||||
self.build_opts.clone(),
|
||||
self.config.clone(),
|
||||
renderer.name().to_string(),
|
||||
);
|
||||
|
||||
LoadedBook::Single(self.preprocess(&preprocess_ctx, renderer, book.clone())?)
|
||||
}
|
||||
};
|
||||
@ -273,10 +282,17 @@ impl MDBook {
|
||||
self
|
||||
}
|
||||
|
||||
fn test_book(&self, book: &Book, temp_dir: &TempDir, library_args: &Vec<&str>) -> Result<()> {
|
||||
fn test_book(
|
||||
&self,
|
||||
book: &Book,
|
||||
temp_dir: &TempDir,
|
||||
library_args: &Vec<&str>,
|
||||
language_ident: Option<String>,
|
||||
) -> Result<()> {
|
||||
// FIXME: Is "test" the proper renderer name to use here?
|
||||
let preprocess_context = PreprocessorContext::new(
|
||||
self.root.clone(),
|
||||
language_ident,
|
||||
self.build_opts.clone(),
|
||||
self.config.clone(),
|
||||
"test".to_string(),
|
||||
|
@ -50,7 +50,8 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
|
||||
|
||||
trigger_on_change(&book, |paths, book_dir| {
|
||||
info!("Files changed: {:?}\nBuilding book...\n", paths);
|
||||
let result = MDBook::load_with_build_opts(&book_dir, build_opts.clone()).and_then(|mut b| {
|
||||
let result =
|
||||
MDBook::load_with_build_opts(&book_dir, build_opts.clone()).and_then(|mut b| {
|
||||
update_config(&mut b);
|
||||
b.build()
|
||||
});
|
||||
|
@ -42,7 +42,11 @@ impl Preprocessor for LinkPreprocessor {
|
||||
}
|
||||
|
||||
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book> {
|
||||
let src_dir = ctx.source_dir();
|
||||
let src_dir = ctx
|
||||
.config
|
||||
.get_localized_src_path(ctx.language_ident.as_ref())
|
||||
.unwrap();
|
||||
let src_dir = ctx.root.join(src_dir);
|
||||
|
||||
book.for_each_mut(|section: &mut BookItem| {
|
||||
if let BookItem::Chapter(ref mut ch) = *section {
|
||||
|
@ -23,6 +23,9 @@ use std::path::PathBuf;
|
||||
pub struct PreprocessorContext {
|
||||
/// The location of the book directory on disk.
|
||||
pub root: PathBuf,
|
||||
/// The language of the book being built. Is only `Some` if the book is part
|
||||
/// of a multilingual build output.
|
||||
pub language_ident: Option<String>,
|
||||
/// The build options passed from the frontend.
|
||||
pub build_opts: BuildOpts,
|
||||
/// The book configuration (`book.toml`).
|
||||
@ -41,12 +44,14 @@ impl PreprocessorContext {
|
||||
/// Create a new `PreprocessorContext`.
|
||||
pub(crate) fn new(
|
||||
root: PathBuf,
|
||||
language_ident: Option<String>,
|
||||
build_opts: BuildOpts,
|
||||
config: Config,
|
||||
renderer: String,
|
||||
) -> Self {
|
||||
PreprocessorContext {
|
||||
root,
|
||||
language_ident,
|
||||
build_opts,
|
||||
config,
|
||||
renderer,
|
||||
|
Loading…
Reference in New Issue
Block a user