Skip to content

fix: make all links in the mdbook preprocessor relative #392

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

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use mdbook::{
preprocess::{Preprocessor, PreprocessorContext},
};
use sections::{Section, SectionData};
use std::sync::OnceLock;
mod argument_visitor;
mod markdown;
mod sections;
Expand All @@ -29,6 +30,8 @@ impl From<&PreprocessorContext> for Options {
}

const LAD_EXTENSION: &str = "lad.json";
// global for options
static OPTIONS: OnceLock<Options> = OnceLock::new();

pub struct LADPreprocessor;

Expand All @@ -49,7 +52,6 @@ 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,
Expand All @@ -64,7 +66,7 @@ impl LADPreprocessor {

let parent_path = parent
.and_then(|p| p.path.clone())
.unwrap_or_else(|| options.root.clone().into())
.unwrap_or_default()
.with_extension("");

log::debug!("Parent path: {:?}", parent_path);
Expand Down Expand Up @@ -99,6 +101,9 @@ impl Preprocessor for LADPreprocessor {
let options = Options::from(context);

log::debug!("Options: {:?}", options);
OPTIONS
.set(options)
.map_err(|_| mdbook::errors::Error::msg("could not initialize options"))?;

// first replace children in parents
book.for_each_mut(|item| {
Expand All @@ -113,7 +118,6 @@ impl Preprocessor for LADPreprocessor {
if LADPreprocessor::is_lad_file(chapter) {
match LADPreprocessor::process_lad_chapter(
context,
&options,
chapter,
Some(parent),
idx,
Expand Down Expand Up @@ -147,7 +151,6 @@ impl Preprocessor for LADPreprocessor {
}
let new_chapter = match LADPreprocessor::process_lad_chapter(
context,
&options,
chapter,
None,
chapter
Expand Down
4 changes: 2 additions & 2 deletions crates/lad_backends/mdbook_lad_preprocessor/src/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<'a> Section<'a> {
}
SectionData::InstancesSummary => {
let instances = self.ladfile.globals.iter().collect::<Vec<_>>();
let types_directory = PathBuf::from("/").join(self.parent_path.join("types"));
let types_directory = PathBuf::from("./types");
vec![SectionItem::InstancesSummary {
instances,
ladfile: self.ladfile,
Expand Down Expand Up @@ -355,7 +355,7 @@ impl<'a> Section<'a> {
]
}
SectionData::FunctionDetail { function } => {
let types_directory = self.parent_path.join("../types");
let types_directory = PathBuf::from("../types");
vec![SectionItem::FunctionDetails {
function,
ladfile: self.ladfile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

| Name | Type | Documentation |
| --- | --- | --- |
| **arg1** | [usize](parent/lad/functions/../types/usize.md) | No Documentation 🚧 |
| **arg1** | [usize](../types/usize.md) | No Documentation 🚧 |

#### Returns

| Name | Type | Documentation |
| --- | --- | --- |
| **arg0** | [usize](parent/lad/functions/../types/usize.md) | No Documentation 🚧 |
| **arg0** | [usize](../types/usize.md) | No Documentation 🚧 |

Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Instances containing actual accessible values\.

| Instance | Type |
| --- | --- |
| `my_non_static_instance` | Vec\<[UnitType](/parent/lad/types/unittype.md)\> |
| `map` | HashMap\<[String](/parent/lad/types/string.md), [String](/parent/lad/types/string.md) \| [String](/parent/lad/types/string.md)\> |
| `my_non_static_instance` | Vec\<[UnitType](./types/unittype.md)\> |
| `map` | HashMap\<[String](./types/string.md), [String](./types/string.md) \| [String](./types/string.md)\> |

### Static Instances

Static type references, existing for the purpose of typed static function calls\.

| Instance | Type |
| --- | --- |
| `my_static_instance` | StructType\<[usize](/parent/lad/types/usize.md)\> |
| `my_static_instance` | StructType\<[usize](./types/usize.md)\> |

Loading