Skip to content

Commit 09f1f15

Browse files
authored
fix: mdbook preprocessor links not taking into account root url (#391)
# Summary - These were broken on the github.io url after I made the links absolute
1 parent 4a670bf commit 09f1f15

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.github/workflows/bencher_on_pr_or_fork_upload.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
workflows: [Run benchmarks on PR]
66
types: [completed]
77

8+
permissions: write-all
9+
810
jobs:
911
track_fork_pr_branch:
1012
if: github.event.workflow_run.conclusion == 'success'

crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ mod argument_visitor;
1010
mod markdown;
1111
mod sections;
1212

13+
#[derive(Debug)]
14+
struct Options {
15+
pub root: String,
16+
}
17+
18+
impl From<&PreprocessorContext> for Options {
19+
fn from(context: &PreprocessorContext) -> Self {
20+
let root = context
21+
.config
22+
.get_preprocessor("lad-preprocessor")
23+
.and_then(|t| t.get("root"))
24+
.and_then(|v| v.as_str())
25+
.map(|s| s.to_owned())
26+
.unwrap_or_default();
27+
Options { root }
28+
}
29+
}
30+
1331
const LAD_EXTENSION: &str = "lad.json";
1432

1533
pub struct LADPreprocessor;
@@ -31,6 +49,7 @@ impl LADPreprocessor {
3149
/// and `chapter_index` is the index of the chapter among its siblings.
3250
fn process_lad_chapter(
3351
_context: &PreprocessorContext,
52+
options: &Options,
3453
chapter: &mdbook::book::Chapter,
3554
parent: Option<&mdbook::book::Chapter>,
3655
chapter_index: usize,
@@ -45,9 +64,11 @@ impl LADPreprocessor {
4564

4665
let parent_path = parent
4766
.and_then(|p| p.path.clone())
48-
.unwrap_or_default()
67+
.unwrap_or_else(|| options.root.clone().into())
4968
.with_extension("");
5069

70+
log::debug!("Parent path: {:?}", parent_path);
71+
5172
let new_chapter = Section::new(
5273
parent_path,
5374
&ladfile,
@@ -75,6 +96,9 @@ impl Preprocessor for LADPreprocessor {
7596
mut book: mdbook::book::Book,
7697
) -> mdbook::errors::Result<mdbook::book::Book> {
7798
let mut errors = Vec::new();
99+
let options = Options::from(context);
100+
101+
log::debug!("Options: {:?}", options);
78102

79103
// first replace children in parents
80104
book.for_each_mut(|item| {
@@ -89,6 +113,7 @@ impl Preprocessor for LADPreprocessor {
89113
if LADPreprocessor::is_lad_file(chapter) {
90114
match LADPreprocessor::process_lad_chapter(
91115
context,
116+
&options,
92117
chapter,
93118
Some(parent),
94119
idx,
@@ -122,6 +147,7 @@ impl Preprocessor for LADPreprocessor {
122147
}
123148
let new_chapter = match LADPreprocessor::process_lad_chapter(
124149
context,
150+
&options,
125151
chapter,
126152
None,
127153
chapter

crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/book.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ description = "Documentation for the Bevy Scripting library"
88

99

1010
[preprocessor.lad-preprocessor]
11-
11+
root = "root"
1212

1313
[output.markdown]

docs/book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ enable = true
1616
level = 1
1717

1818
[preprocessor.lad-preprocessor]
19+
root = "bevy_mod_scripting"

0 commit comments

Comments
 (0)