Merge pull request #339 from mainmatter/push-xrzmzzmtzywz
update to mdbook 0.5
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -47,7 +47,7 @@ jobs:
|
|||||||
run: cargo install --path helpers/mdbook-link-shortener
|
run: cargo install --path helpers/mdbook-link-shortener
|
||||||
- name: Install mdbook-pandoc, calibre, pdftk and related dependencies
|
- name: Install mdbook-pandoc, calibre, pdftk and related dependencies
|
||||||
run: |
|
run: |
|
||||||
cargo install mdbook-pandoc --locked --version 0.7.1
|
cargo install mdbook-pandoc --locked --version 0.11.0
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y fonts-noto fonts-open-sans calibre pdftk
|
sudo apt-get install -y fonts-noto fonts-open-sans calibre pdftk
|
||||||
sudo fc-cache -f -v
|
sudo fc-cache -f -v
|
||||||
|
|||||||
2039
Cargo.lock
generated
2039
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,6 @@
|
|||||||
[book]
|
[book]
|
||||||
authors = ["Luca Palmieri"]
|
authors = ["Luca Palmieri"]
|
||||||
language = "en"
|
language = "en"
|
||||||
multilingual = false
|
|
||||||
src = "src"
|
src = "src"
|
||||||
title = "100 Exercises To Learn Rust"
|
title = "100 Exercises To Learn Rust"
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ edition = "2021"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.100"
|
anyhow = "1.0.100"
|
||||||
clap = "4.5.50"
|
clap = "4.5.50"
|
||||||
mdbook = "0.4.52"
|
mdbook-preprocessor = "0.5.3"
|
||||||
semver = "1.0.27"
|
semver = "1.0.27"
|
||||||
serde_json = "1.0.145"
|
serde_json = "1.0.145"
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use anyhow::{Context, Error};
|
use anyhow::{Context, Error};
|
||||||
use mdbook::book::Book;
|
use mdbook_preprocessor::book::{Book, BookItem};
|
||||||
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
|
use mdbook_preprocessor::{Preprocessor, PreprocessorContext};
|
||||||
use mdbook::BookItem;
|
|
||||||
|
|
||||||
pub struct ExerciseLinker;
|
pub struct ExerciseLinker;
|
||||||
|
|
||||||
@@ -17,27 +16,20 @@ impl Preprocessor for ExerciseLinker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book, Error> {
|
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book, Error> {
|
||||||
let config = ctx
|
let root_url: String = ctx
|
||||||
.config
|
.config
|
||||||
.get_preprocessor(self.name())
|
.get("preprocessor.exercise-linker.exercise_root_url")
|
||||||
.context("Failed to get preprocessor configuration")?;
|
.context("Failed to get `exercise_root_url`")?
|
||||||
let key = String::from("exercise_root_url");
|
.context("`exercise_root_url` is not set")?;
|
||||||
let root_url = config
|
|
||||||
.get(&key)
|
|
||||||
.context("Failed to get `exercise_root_url`")?;
|
|
||||||
let root_url = root_url
|
|
||||||
.as_str()
|
|
||||||
.context("`exercise_root_url` is not a string")?
|
|
||||||
.to_owned();
|
|
||||||
|
|
||||||
book.sections
|
book.items
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.for_each(|i| process_book_item(i, &ctx.renderer, &root_url));
|
.for_each(|i| process_book_item(i, &ctx.renderer, &root_url));
|
||||||
Ok(book)
|
Ok(book)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn supports_renderer(&self, _renderer: &str) -> bool {
|
fn supports_renderer(&self, _renderer: &str) -> mdbook_preprocessor::errors::Result<bool> {
|
||||||
true
|
Ok(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ use std::io;
|
|||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use clap::{Arg, ArgMatches, Command};
|
use clap::{Arg, ArgMatches, Command};
|
||||||
use mdbook::errors::Error;
|
use mdbook_preprocessor::{Preprocessor, MDBOOK_VERSION};
|
||||||
use mdbook::preprocess::{CmdPreprocessor, Preprocessor};
|
|
||||||
use semver::{Version, VersionReq};
|
use semver::{Version, VersionReq};
|
||||||
|
|
||||||
use mdbook_exercise_linker::ExerciseLinker;
|
use mdbook_exercise_linker::ExerciseLinker;
|
||||||
@@ -30,18 +29,18 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
|
fn handle_preprocessing(pre: &dyn Preprocessor) -> anyhow::Result<()> {
|
||||||
let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())?;
|
let (ctx, book) = mdbook_preprocessor::parse_input(io::stdin())?;
|
||||||
|
|
||||||
let book_version = Version::parse(&ctx.mdbook_version)?;
|
let book_version = Version::parse(&ctx.mdbook_version)?;
|
||||||
let version_req = VersionReq::parse(mdbook::MDBOOK_VERSION)?;
|
let version_req = VersionReq::parse(MDBOOK_VERSION)?;
|
||||||
|
|
||||||
if !version_req.matches(&book_version) {
|
if !version_req.matches(&book_version) {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Warning: The {} plugin was built against version {} of mdbook, \
|
"Warning: The {} plugin was built against version {} of mdbook, \
|
||||||
but we're being called from version {}",
|
but we're being called from version {}",
|
||||||
pre.name(),
|
pre.name(),
|
||||||
mdbook::MDBOOK_VERSION,
|
MDBOOK_VERSION,
|
||||||
ctx.mdbook_version
|
ctx.mdbook_version
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -56,7 +55,9 @@ fn handle_supports(pre: &dyn Preprocessor, sub_args: &ArgMatches) -> ! {
|
|||||||
let renderer = sub_args
|
let renderer = sub_args
|
||||||
.get_one::<String>("renderer")
|
.get_one::<String>("renderer")
|
||||||
.expect("Required argument");
|
.expect("Required argument");
|
||||||
let supported = pre.supports_renderer(renderer);
|
let supported = pre
|
||||||
|
.supports_renderer(renderer)
|
||||||
|
.expect("Failed to check renderer support");
|
||||||
|
|
||||||
// Signal whether the renderer is supported by exiting with 1 or 0.
|
// Signal whether the renderer is supported by exiting with 1 or 0.
|
||||||
if supported {
|
if supported {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ anyhow = "1.0.100"
|
|||||||
bimap = { version = "0.6.3", features = ["serde"] }
|
bimap = { version = "0.6.3", features = ["serde"] }
|
||||||
clap = { version = "4.5.50", features = ["derive"] }
|
clap = { version = "4.5.50", features = ["derive"] }
|
||||||
itertools = "0.13.0"
|
itertools = "0.13.0"
|
||||||
mdbook = "0.4.52"
|
mdbook-preprocessor = "0.5.3"
|
||||||
pulldown-cmark = "0.11.3"
|
pulldown-cmark = "0.11.3"
|
||||||
pulldown-cmark-to-cmark = "15"
|
pulldown-cmark-to-cmark = "15"
|
||||||
semver = "1.0.27"
|
semver = "1.0.27"
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
use anyhow::{Context, Error};
|
use anyhow::{Context, Error};
|
||||||
use bimap::BiHashMap;
|
use bimap::BiHashMap;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use mdbook::book::{Book, Chapter};
|
use mdbook_preprocessor::book::{Book, BookItem, Chapter};
|
||||||
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
|
use mdbook_preprocessor::{Preprocessor, PreprocessorContext};
|
||||||
use mdbook::BookItem;
|
|
||||||
use std::collections::{BTreeMap, BTreeSet};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@@ -65,23 +64,17 @@ impl Preprocessor for LinkShortener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book, Error> {
|
fn run(&self, ctx: &PreprocessorContext, mut book: Book) -> Result<Book, Error> {
|
||||||
let config = ctx
|
let root_url: String = ctx
|
||||||
.config
|
.config
|
||||||
.get_preprocessor(self.name())
|
.get("preprocessor.link-shortener.base_url")
|
||||||
.context("Failed to get preprocessor configuration")?;
|
.context("Failed to get `base_url`")?
|
||||||
let root_url = {
|
.context("`base_url` is not set")?;
|
||||||
let root_url = config.get("base_url").context("Failed to get `base_url`")?;
|
|
||||||
root_url
|
|
||||||
.as_str()
|
|
||||||
.context("`base_url` is not a string")?
|
|
||||||
.to_owned()
|
|
||||||
};
|
|
||||||
let mapping = {
|
let mapping = {
|
||||||
let mapping = config.get("mapping").context("Failed to get `mapping`")?;
|
let mapping: String = ctx
|
||||||
let mapping = mapping
|
.config
|
||||||
.as_str()
|
.get("preprocessor.link-shortener.mapping")
|
||||||
.context("`mapping` is not a string")?
|
.context("Failed to get `mapping`")?
|
||||||
.to_owned();
|
.context("`mapping` is not set")?;
|
||||||
PathBuf::from_str(&mapping).context("Failed to parse `mapping` as a path")?
|
PathBuf::from_str(&mapping).context("Failed to parse `mapping` as a path")?
|
||||||
};
|
};
|
||||||
let mut link2alias = {
|
let mut link2alias = {
|
||||||
@@ -98,11 +91,11 @@ impl Preprocessor for LinkShortener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let verify = config
|
let verify: bool = ctx
|
||||||
.get("verify")
|
.config
|
||||||
|
.get("preprocessor.link-shortener.verify")
|
||||||
.context("Failed to get `verify`")?
|
.context("Failed to get `verify`")?
|
||||||
.as_bool()
|
.context("`verify` is not set")?;
|
||||||
.context("`verify` is not a boolean")?;
|
|
||||||
// Env var overrides config
|
// Env var overrides config
|
||||||
let verify = std::env::var("LINK_SHORTENER_VERIFY")
|
let verify = std::env::var("LINK_SHORTENER_VERIFY")
|
||||||
.map(|v| v == "true")
|
.map(|v| v == "true")
|
||||||
@@ -110,7 +103,7 @@ impl Preprocessor for LinkShortener {
|
|||||||
|
|
||||||
let mut alias_gen = AliasGenerator::new();
|
let mut alias_gen = AliasGenerator::new();
|
||||||
|
|
||||||
book.sections.iter_mut().for_each(|i| {
|
book.items.iter_mut().for_each(|i| {
|
||||||
if let BookItem::Chapter(c) = i {
|
if let BookItem::Chapter(c) = i {
|
||||||
c.content = replace_anchors(c, &root_url, &mut alias_gen, &mut link2alias, verify)
|
c.content = replace_anchors(c, &root_url, &mut alias_gen, &mut link2alias, verify)
|
||||||
.expect("Error converting links for chapter");
|
.expect("Error converting links for chapter");
|
||||||
@@ -139,8 +132,8 @@ impl Preprocessor for LinkShortener {
|
|||||||
Ok(book)
|
Ok(book)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn supports_renderer(&self, _renderer: &str) -> bool {
|
fn supports_renderer(&self, _renderer: &str) -> mdbook_preprocessor::errors::Result<bool> {
|
||||||
true
|
Ok(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use mdbook::errors::Error;
|
|
||||||
use mdbook::preprocess::{CmdPreprocessor, Preprocessor};
|
|
||||||
use mdbook_link_shortener::LinkShortener;
|
use mdbook_link_shortener::LinkShortener;
|
||||||
|
use mdbook_preprocessor::{Preprocessor, MDBOOK_VERSION};
|
||||||
use semver::{Version, VersionReq};
|
use semver::{Version, VersionReq};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::process;
|
use std::process;
|
||||||
@@ -30,7 +29,10 @@ fn main() -> Result<(), anyhow::Error> {
|
|||||||
let preprocessor = LinkShortener::new();
|
let preprocessor = LinkShortener::new();
|
||||||
|
|
||||||
if let Some(SubCommand::Supports(Supports { renderer })) = cli.sub {
|
if let Some(SubCommand::Supports(Supports { renderer })) = cli.sub {
|
||||||
let code = if preprocessor.supports_renderer(&renderer) {
|
let code = if preprocessor
|
||||||
|
.supports_renderer(&renderer)
|
||||||
|
.expect("Failed to check renderer support")
|
||||||
|
{
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
1
|
1
|
||||||
@@ -43,18 +45,18 @@ fn main() -> Result<(), anyhow::Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_preprocessing(pre: &dyn Preprocessor) -> Result<(), Error> {
|
fn handle_preprocessing(pre: &dyn Preprocessor) -> anyhow::Result<()> {
|
||||||
let (ctx, book) = CmdPreprocessor::parse_input(io::stdin())?;
|
let (ctx, book) = mdbook_preprocessor::parse_input(io::stdin())?;
|
||||||
|
|
||||||
let book_version = Version::parse(&ctx.mdbook_version)?;
|
let book_version = Version::parse(&ctx.mdbook_version)?;
|
||||||
let version_req = VersionReq::parse(mdbook::MDBOOK_VERSION)?;
|
let version_req = VersionReq::parse(MDBOOK_VERSION)?;
|
||||||
|
|
||||||
if !version_req.matches(&book_version) {
|
if !version_req.matches(&book_version) {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"Warning: The {} plugin was built against version {} of mdbook, \
|
"Warning: The {} plugin was built against version {} of mdbook, \
|
||||||
but we're being called from version {}",
|
but we're being called from version {}",
|
||||||
pre.name(),
|
pre.name(),
|
||||||
mdbook::MDBOOK_VERSION,
|
MDBOOK_VERSION,
|
||||||
ctx.mdbook_version
|
ctx.mdbook_version
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user