Skip to content

Commit

Permalink
Use filepath field instead of url field to calculate file path (mozil…
Browse files Browse the repository at this point in the history
…la#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.
  • Loading branch information
hoodmane authored Oct 1, 2023
1 parent 775cdf4 commit b8597e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
15 changes: 4 additions & 11 deletions sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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] += "/"
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_typedoc_analysis/test_typedoc_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ def test_top_level_function(self):
# things get paths
assert function.path == [
"./",
"test_typedoc_analysis/",
"source/",
"longnames.",
"foo",
]
Expand Down

0 comments on commit b8597e4

Please sign in to comment.