diff --git a/.github/workflows/bencher_on_pr_or_fork_upload.yml b/.github/workflows/bencher_on_pr_or_fork_upload.yml index 38442c96ec..3c3204d701 100644 --- a/.github/workflows/bencher_on_pr_or_fork_upload.yml +++ b/.github/workflows/bencher_on_pr_or_fork_upload.yml @@ -5,6 +5,8 @@ on: workflows: [Run benchmarks on PR] types: [completed] +permissions: write-all + jobs: track_fork_pr_branch: if: github.event.workflow_run.conclusion == 'success' diff --git a/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs b/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs index 4304945d20..bacb7a2bdb 100644 --- a/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs +++ b/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs @@ -10,6 +10,24 @@ mod argument_visitor; mod markdown; mod sections; +#[derive(Debug)] +struct Options { + pub root: String, +} + +impl From<&PreprocessorContext> for Options { + fn from(context: &PreprocessorContext) -> Self { + let root = context + .config + .get_preprocessor("lad-preprocessor") + .and_then(|t| t.get("root")) + .and_then(|v| v.as_str()) + .map(|s| s.to_owned()) + .unwrap_or_default(); + Options { root } + } +} + const LAD_EXTENSION: &str = "lad.json"; pub struct LADPreprocessor; @@ -31,6 +49,7 @@ impl LADPreprocessor { /// and `chapter_index` is the index of the chapter among its siblings. fn process_lad_chapter( _context: &PreprocessorContext, + options: &Options, chapter: &mdbook::book::Chapter, parent: Option<&mdbook::book::Chapter>, chapter_index: usize, @@ -45,9 +64,11 @@ impl LADPreprocessor { let parent_path = parent .and_then(|p| p.path.clone()) - .unwrap_or_default() + .unwrap_or_else(|| options.root.clone().into()) .with_extension(""); + log::debug!("Parent path: {:?}", parent_path); + let new_chapter = Section::new( parent_path, &ladfile, @@ -75,6 +96,9 @@ impl Preprocessor for LADPreprocessor { mut book: mdbook::book::Book, ) -> mdbook::errors::Result { let mut errors = Vec::new(); + let options = Options::from(context); + + log::debug!("Options: {:?}", options); // first replace children in parents book.for_each_mut(|item| { @@ -89,6 +113,7 @@ impl Preprocessor for LADPreprocessor { if LADPreprocessor::is_lad_file(chapter) { match LADPreprocessor::process_lad_chapter( context, + &options, chapter, Some(parent), idx, @@ -122,6 +147,7 @@ impl Preprocessor for LADPreprocessor { } let new_chapter = match LADPreprocessor::process_lad_chapter( context, + &options, chapter, None, chapter diff --git a/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/book.toml b/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/book.toml index 0620453489..8c84c8e7f9 100644 --- a/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/book.toml +++ b/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/book.toml @@ -8,6 +8,6 @@ description = "Documentation for the Bevy Scripting library" [preprocessor.lad-preprocessor] - +root = "root" [output.markdown] diff --git a/docs/book.toml b/docs/book.toml index b347b4786a..6728e0f0ee 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -16,3 +16,4 @@ enable = true level = 1 [preprocessor.lad-preprocessor] +root = "bevy_mod_scripting"