mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Use chapter.source_path for partial includes, not chapter.path

Open petersooley opened this issue 4 years ago • 3 comments

Partial includes are found using relative paths, but relies on the logical path variable rather than the actual source_path.

The Chapter::source_path property was introduced to render URLs differently from how they might be on the filesystem. It's a good change that allows preprocessors to do more with the rendered URLs, but that almost always breaks the links preprocessor. This PR switches to using source_path when looking up relative partial paths.

petersooley avatar Dec 31 '21 22:12 petersooley

Thanks! Can you say more about what situation involves changing the path in such a way that breaks the links preprocessor?

Also, can you add a test for this?

ehuss avatar Jan 03 '22 19:01 ehuss

I have a preprocessor mdbook-fs-summary that uses filename prefixes and indicators to generate the summary from the filesystem, but I'd like to strip these indicators from the resulting URLs. It generates BookItem::Chapter(Chapter) where path captures the intended URL path and source_path as the location of the file.

Other preprocessors offering similar behavior of wanting to alter the URL without losing access to the underlying filesystem paths would benefit from this. Like for #1258.

As far as tests go, I've added a new test to validate that the Chapter::path can be maintained differently from Chapter::source_path which is ultimately the API I'm inferring with this PR. Turns out this currently fails as there are still places in the overall project that use Chapter::path when it should probably use Chapter::source_path.

I can continue pursuing this to get to a point where this test passes. Please let me know if this is the wrong direction.

petersooley avatar Jan 05 '22 12:01 petersooley

:umbrella: The latest upstream changes (possibly #2681) made this pull request unmergeable. Please resolve the merge conflicts.

rustbot avatar Apr 30 '25 13:04 rustbot