Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed the MDBook::execute_build_process() method to 3rd parties #1099

Merged

Conversation

Michael-F-Bryan
Copy link
Contributor

@Michael-F-Bryan Michael-F-Bryan commented Nov 17, 2019

I think it's pretty common for 3rd party backends to expose some sort of --standalone flag so you could (for example) run mdbook-linkcheck --standalone user-guide to load the book and execute just that renderer.

Exposing the MDBook::execute_build_process() means we can replace this manual construction of a RenderContext and invoking the rendering system:

    // get a `RenderContext`, either from stdin (because we're used as a plugin)
    // or by instrumenting MDBook directly (in standalone mode).
    let ctx: RenderContext = if args.standalone {
        let md = MDBook::load(dunce::canonicalize(&args.root)?)
            .map_err(SyncFailure::new)?;
        let destination = md.build_dir_for("linkcheck");
        RenderContext::new(md.root, md.book, md.config, destination)
    } else {
        serde_json::from_reader(io::stdin())
            .context("Unable to parse RenderContext")?
    };

    let cache_file = ctx.destination.join("cache.json");
    mdbook_linkcheck::run(&cache_file, args.colour, &ctx)

With something like this:

let renderer = Renderer::new();

if is_standalone {
    let book = MDBook::load(&args.book_directory)?;
    book.execute_build_process(&renderer)?;
} else {
    let ctx = RenderContext::from_json(io::stdin())?;
    renderer.run(&ctx)?;
}

EDIT: Looking more closely, I think mdbook-linkcheck isn't even doing things correctly here. We forget to run all applicable preprocessors over the book because it's trying to execute the rendering pipeline manually.

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable.

@ehuss ehuss merged commit 7def6d7 into rust-lang:master Nov 23, 2019
@Michael-F-Bryan Michael-F-Bryan deleted the expose-execute-build-process branch November 24, 2019 02:33
Ruin0x11 pushed a commit to Ruin0x11/mdBook that referenced this pull request Aug 30, 2020
…-build-process

Exposed the MDBook::execute_build_process() method to 3rd parties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants