Skip to content

Commit

Permalink
fix(theme_dir): consider the custom theme dir
Browse files Browse the repository at this point in the history
close #6
  • Loading branch information
zjp-CN committed Apr 5, 2023
1 parent 1a509ca commit 60896c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bin/mdbook-theme-ace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() -> Result<()> {
.ok_or(Error::DeserializedFailed)?;
cfg.build_dir = ctx.root.join(&ctx.config.build.build_dir);
cfg.destination = ctx.root.join(&ctx.destination);
cfg.theme_dir = theme_dir(&ctx.root);
cfg.theme_dir = theme_dir(&ctx.root, &ctx.config);

cfg.run()
}
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use mdbook::{
book::Book,
errors,
preprocess::{Preprocessor, PreprocessorContext},
Config,
};
use std::{
path::{Path, PathBuf},
Expand Down Expand Up @@ -40,9 +41,14 @@ pub type Result<T> = std::result::Result<T, Error>;

pub struct PreTheme;

/// `./theme` dir
pub fn theme_dir(root: &Path) -> PathBuf {
root.join("theme")
/// absoulte path to theme dir:
/// if `output.html.theme` is not provided, it defaults to `theme/`
pub fn theme_dir(root: &Path, config: &Config) -> PathBuf {
let theme_dir_ = config
.get("output.html.theme")
.and_then(|v| v.as_str())
.unwrap_or("theme");
root.join(theme_dir_)
}

impl Preprocessor for PreTheme {
Expand All @@ -51,7 +57,7 @@ impl Preprocessor for PreTheme {
}

fn run(&self, ctx: &PreprocessorContext, book: Book) -> result::Result<Book, errors::Error> {
let dir = theme_dir(&ctx.root);
let dir = theme_dir(&ctx.root, &ctx.config);
if let Some(theme) = ctx.config.get_preprocessor(self.name()) {
theme::config::run(theme, dir);
}
Expand Down

0 comments on commit 60896c7

Please sign in to comment.