backstage / mkdocs-monorepo-plugin

✚ Build multiple documentation folders in a single Mkdocs. Designed for large codebases.
https://backstage.github.io/mkdocs-monorepo-plugin/
Apache License 2.0
314 stars 75 forks source link

Check whether the page source is in this plugins control #42

Closed rwittrick closed 3 years ago

rwittrick commented 3 years ago

If another plugin modifies the sources, it's not always true that this plugins files_source_dir dict will always contain the page.file.abs_src_path, and therefore this might throw an error:

From https://github.com/backstage/mkdocs-monorepo-plugin/blob/440382ac5825476ac6249c7808ce556d04173b0c/mkdocs_monorepo_plugin/plugin.py#L62

    def on_pre_page(self, page, config, files):
        # Update page source attribute to point to source file
        # Only in case any files were moved.
        if len(self.files_source_dir) > 0:
            page.file.abs_src_path = self.files_source_dir[page.file.abs_src_path]
        return page

This code should check whether it was "managing" the source for the page via

 if len(self.files_source_dir) > 0 && page.file.abs_src_path in self.files_source_dir:

before trying to change it (at Line 62 of plugin.py)