From b8597e4626bed505f1fa50713c417552d58a9054 Mon Sep 17 00:00:00 2001 From: Hood Chatham Date: Sat, 30 Sep 2023 17:19:09 -0700 Subject: [PATCH] Use filepath field instead of url field to calculate file path (#103) In retrospect the filepath field already has what I needed, the trick is setting basePath. This leaves the URL field available for linking to the source. --- sphinx_js/typedoc.py | 15 ++++----------- .../test_typedoc_analysis.py | 2 -- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/sphinx_js/typedoc.py b/sphinx_js/typedoc.py index 23c192f2..ca9f9a63 100644 --- a/sphinx_js/typedoc.py +++ b/sphinx_js/typedoc.py @@ -73,13 +73,6 @@ def typedoc_output( tsconfig_path = str((Path(sphinx_conf_dir) / config_path).absolute()) command.add("--tsconfig", tsconfig_path) - # We want to use the url field to compute the file paths. - - # --disableGit prevents typedoc from doing complicated magic with git that - # makes the url field harder to understand. - command.add("--disableGit") - # sourceLinkTemplate makes the url field contain just the file path - command.add("--sourceLinkTemplate", "{path}") command.add("--basePath", base_dir) with NamedTemporaryFile(mode="w+b", delete=False) as temp: @@ -141,10 +134,10 @@ def populate_index(self, root: "IndexType") -> "Converter": self._populate_index_inner(root, parent=None) return self - def _url_to_filepath(self, url: str) -> list[str]: - if not url: + def _parse_filepath(self, path: str) -> list[str]: + if not path: return [] - entries = ["."] + url.split("/") + entries = ["."] + path.split("/") entries[-1] = entries[-1].rpartition(".")[0] for i in range(len(entries) - 1): entries[i] += "/" @@ -162,7 +155,7 @@ def _populate_index_inner( parent_kind = parent.kindString if parent else "" parent_segments = parent.path if parent else [] if node.sources: - filepath = self._url_to_filepath(node.sources[0].url) + filepath = self._parse_filepath(node.sources[0].fileName) if filepath: node.filepath = filepath self.compute_path(node, parent_kind, parent_segments, filepath) diff --git a/tests/test_typedoc_analysis/test_typedoc_analysis.py b/tests/test_typedoc_analysis/test_typedoc_analysis.py index 9567dd69..15c6d2ad 100644 --- a/tests/test_typedoc_analysis/test_typedoc_analysis.py +++ b/tests/test_typedoc_analysis/test_typedoc_analysis.py @@ -93,8 +93,6 @@ def test_top_level_function(self): # things get paths assert function.path == [ "./", - "test_typedoc_analysis/", - "source/", "longnames.", "foo", ]