1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-17 16:12:39 +02:00
Dustin J. Mitchell 4815264e2d
Add mdbook-course to handle parsing frontmatter (#1224)
In v2 of the course, I'd like to include an estimate of the time to be
spent on each segment in the Markdown file. I think a good place for
such metadata is in the frontmatter.

For review purposes, though, I just want to display that information.
So, this is a start at a new mdbook preprocessor that just separates out
the frontmatter and includes it in a `<pre>` block. Eventually, I'd like
to parse it and put the time in the speaker notes.

---------

Co-authored-by: Martin Geisler <martin@geisler.net>
2023-09-20 10:01:53 -04:00

47 lines
1.4 KiB
Rust

// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use clap::{Arg, Command};
use mdbook::preprocess::CmdPreprocessor;
use mdbook_course::frontmatter::remove_frontmatter;
use std::io::{stdin, stdout};
use std::process;
fn main() {
pretty_env_logger::init();
let app = Command::new("mdbook-course")
.about("mdbook preprocessor for Comprehensive Rust")
.subcommand(Command::new("supports").arg(Arg::new("renderer").required(true)));
let matches = app.get_matches();
if let Some(_) = matches.subcommand_matches("supports") {
// Support all renderers.
process::exit(0);
}
if let Err(e) = preprocess() {
eprintln!("{}", e);
process::exit(1);
}
}
fn preprocess() -> anyhow::Result<()> {
let (ctx, mut book) = CmdPreprocessor::parse_input(stdin())?;
remove_frontmatter(&ctx, &mut book)?;
serde_json::to_writer(stdout(), &book)?;
Ok(())
}