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)
|
- [Syntax highlighting](format/theme/syntax-highlighting.md)
|
||||||
- [Editor](format/theme/editor.md)
|
- [Editor](format/theme/editor.md)
|
||||||
- [MathJax Support](format/mathjax.md)
|
- [MathJax Support](format/mathjax.md)
|
||||||
|
- [Localization](format/localization.md)
|
||||||
- [mdBook-specific features](format/mdbook.md)
|
- [mdBook-specific features](format/mdbook.md)
|
||||||
- [Continuous Integration](continuous-integration.md)
|
- [Continuous Integration](continuous-integration.md)
|
||||||
- [For Developers](for_developers/README.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`].
|
/// Run the entire build process for a particular [`Renderer`].
|
||||||
pub fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()> {
|
pub fn execute_build_process(&self, renderer: &dyn Renderer) -> Result<()> {
|
||||||
let preprocess_ctx = PreprocessorContext::new(
|
|
||||||
self.root.clone(),
|
|
||||||
self.build_opts.clone(),
|
|
||||||
self.config.clone(),
|
|
||||||
renderer.name().to_string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let preprocessed_books = match &self.book {
|
let preprocessed_books = match &self.book {
|
||||||
LoadedBook::Localized(ref books) => {
|
LoadedBook::Localized(ref books) => {
|
||||||
let mut new_books = HashMap::new();
|
let mut new_books = HashMap::new();
|
||||||
|
|
||||||
for (ident, book) in books.0.iter() {
|
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_book =
|
let preprocessed_book =
|
||||||
self.preprocess(&preprocess_ctx, renderer, book.clone())?;
|
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::Localized(LocalizedBooks(new_books))
|
||||||
}
|
}
|
||||||
LoadedBook::Single(ref book) => {
|
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())?)
|
LoadedBook::Single(self.preprocess(&preprocess_ctx, renderer, book.clone())?)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -273,10 +282,17 @@ impl MDBook {
|
|||||||
self
|
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?
|
// FIXME: Is "test" the proper renderer name to use here?
|
||||||
let preprocess_context = PreprocessorContext::new(
|
let preprocess_context = PreprocessorContext::new(
|
||||||
self.root.clone(),
|
self.root.clone(),
|
||||||
|
language_ident,
|
||||||
self.build_opts.clone(),
|
self.build_opts.clone(),
|
||||||
self.config.clone(),
|
self.config.clone(),
|
||||||
"test".to_string(),
|
"test".to_string(),
|
||||||
|
@ -50,10 +50,11 @@ pub fn execute(args: &ArgMatches) -> Result<()> {
|
|||||||
|
|
||||||
trigger_on_change(&book, |paths, book_dir| {
|
trigger_on_change(&book, |paths, book_dir| {
|
||||||
info!("Files changed: {:?}\nBuilding book...\n", paths);
|
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 =
|
||||||
update_config(&mut b);
|
MDBook::load_with_build_opts(&book_dir, build_opts.clone()).and_then(|mut b| {
|
||||||
b.build()
|
update_config(&mut b);
|
||||||
});
|
b.build()
|
||||||
|
});
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
error!("Unable to build the book");
|
error!("Unable to build the book");
|
||||||
|
@ -42,7 +42,11 @@ impl Preprocessor for LinkPreprocessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book> {
|
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| {
|
book.for_each_mut(|section: &mut BookItem| {
|
||||||
if let BookItem::Chapter(ref mut ch) = *section {
|
if let BookItem::Chapter(ref mut ch) = *section {
|
||||||
|
@ -23,6 +23,9 @@ use std::path::PathBuf;
|
|||||||
pub struct PreprocessorContext {
|
pub struct PreprocessorContext {
|
||||||
/// The location of the book directory on disk.
|
/// The location of the book directory on disk.
|
||||||
pub root: PathBuf,
|
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.
|
/// The build options passed from the frontend.
|
||||||
pub build_opts: BuildOpts,
|
pub build_opts: BuildOpts,
|
||||||
/// The book configuration (`book.toml`).
|
/// The book configuration (`book.toml`).
|
||||||
@ -41,12 +44,14 @@ impl PreprocessorContext {
|
|||||||
/// Create a new `PreprocessorContext`.
|
/// Create a new `PreprocessorContext`.
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
root: PathBuf,
|
root: PathBuf,
|
||||||
|
language_ident: Option<String>,
|
||||||
build_opts: BuildOpts,
|
build_opts: BuildOpts,
|
||||||
config: Config,
|
config: Config,
|
||||||
renderer: String,
|
renderer: String,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
PreprocessorContext {
|
PreprocessorContext {
|
||||||
root,
|
root,
|
||||||
|
language_ident,
|
||||||
build_opts,
|
build_opts,
|
||||||
config,
|
config,
|
||||||
renderer,
|
renderer,
|
||||||
|
Loading…
Reference in New Issue
Block a user