typedoc2md / typedoc-plugin-markdown

A plugin for TypeDoc that enables TypeScript API documentation to be generated in Markdown.
https://typedoc-plugin-markdown.org
MIT License
697 stars 173 forks source link

[typedoc-plugin-markdown@next] Bug: Links to `README.md` in header broken in member pages. #483

Closed sharky98 closed 9 months ago

sharky98 commented 10 months ago

Hello,

I have an issue where the links to the module README.md files are not relative from the member pages when building a doc for a monorepository ("entryPointStrategy": "packages", based on Gerrit0 example).

Version: 4.0.0-next.23(typedoc@0.25.1)

I am using the default outputFileStrategy (members).

For example, taking the tree shown in the option guide.

In the page ClassA.md, the header would uses [README](README.md) ∙ [API](../modules.md) for the links, correctly using the relative for the modules.md page, but not for the README.md page.

It is to note that the breadcrumbs do get relative links as expected, but they all point to the modules files, which already get its relative links correctly in the header.

[API](../../../modules.md) > [package-1](../modules.md) > Content

monorepo
├── README.md
├── modules.md
├── package-a
├── ├── README.md
├── ├── modules.md
│   ├── classes
│   │   ├── ClassA.md
│   │   ├── ClassB.md
├── ├── variables
│   │   ├── VariableA.md
│   │   ├── VariableB.md
├── package-b
├── ├── README.md
├── ├── modules.md
│   ├── classes
│   │   ├── ClassA.md
│   │   ├── ClassB.md
├── ├── variables
│   │   ├── VariableA.md
│   │   ├── VariableB.md

I was looking at the tests, and I'm not sure if I am reading this right, but it looks that this case is not covered. Seems that

https://github.com/tgreyuk/typedoc-plugin-markdown/blob/3a0a5bea81b14857d387fbfba599200212634eeb/packages/typedoc-plugin-markdown/test/specs/__snapshots__/readmes.spec.ts.snap#L20-L48

https://github.com/tgreyuk/typedoc-plugin-markdown/blob/3a0a5bea81b14857d387fbfba599200212634eeb/packages/typedoc-plugin-markdown/test/specs/__snapshots__/navigation.spec.ts.snap#L3-L44

https://github.com/tgreyuk/typedoc-plugin-markdown/blob/3a0a5bea81b14857d387fbfba599200212634eeb/packages/typedoc-plugin-markdown/test/specs/__snapshots__/groups.spec.ts.snap#L493-L509

https://github.com/tgreyuk/typedoc-plugin-markdown/blob/3a0a5bea81b14857d387fbfba599200212634eeb/packages/typedoc-plugin-markdown/test/specs/__snapshots__/urls.spec.ts.snap#L113-L124

sharky98 commented 10 months ago

Could this be the culprit? 🧐

function packageHeader() not using context.relativeURL()

https://github.com/tgreyuk/typedoc-plugin-markdown/blob/3a0a5bea81b14857d387fbfba599200212634eeb/packages/typedoc-plugin-markdown/src/theme/resources/partials/header.ts#L86-L88

Compared to function projectHeader() using context.relativeURL()

https://github.com/tgreyuk/typedoc-plugin-markdown/blob/3a0a5bea81b14857d387fbfba599200212634eeb/packages/typedoc-plugin-markdown/src/theme/resources/partials/header.ts#L51-L53

EDIT: I tried monkey patching it and it did create relative links, but to the root project README.md file, not the package README.md file.

EDIT 2: I trying to figure out some more using some console.log in that header.ts file. However, I was taken aback a bit. It seems that the package-a and package-b README.md and modules.md files are correctly created. However, that README.md file of the package seems to be absent from there. As such, when in package-a/classes/ClassA.md, the context consider monorepo as its parent package (in fact using the project term) and not package-a. I am lost from there. Will wait for your feedback! 🙃

EDIT 3: In any case, the markdown output is WAY better than the v3! 🎉✨ I love it!

tgreyuk commented 10 months ago

Thanks for feedback and the detailed description is very much appreciated. You were on the right lines about including the relativeUrl method, but the url needed to include the package directory.

Fix in typedoc-plugin-markdown@4.0.0-next.24 .