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
725 stars 177 forks source link

Vitepress: Make `basePath` configurable #540

Closed gossi closed 10 months ago

gossi commented 10 months ago

Hej Hej,

I went experimental and trying the vitepress integration. I must say it is fantastic and I really like it, great job there 👏

One thing I noticed, is the basePath is not configurable and depends on your physical folder structure, rather than your documentation structure. That is the outDir is hardcoded for links here:

https://github.com/tgreyuk/typedoc-plugin-markdown/blob/4c6fe809ad7335316ca21ca8d032318965c45b32/packages/typedoc-vitepress-theme/src/index.ts#L49

If it shares the same purpose, then use basePath from typedoc itself - that at least my first go to. Alternatively, I'd expect this to be part of the vitepress options.


My workaround for now:

// package.json
{
  "scripts": {
    "api": "rm -rf docs/api/ && typedoc && mv api/ docs/"
  }
}
tgreyuk commented 10 months ago

Hi,

So just to clarify 100% what your issue is.

a) Currently it is assumed that TypeDoc is running off the VitePress root. So assuming you are running from the VitePress root you should just be able to just pass in the out option i.e.

typedoc --out ./docs/api

That should setup the paths correctly.

b) If you are not running TypeDoc from the VitePress root then we will need another option named something likevitepressRoot that defaults to ./. Should probably expose something like that anyway.

gossi commented 10 months ago

I'm sorry, my bad to not make this more clear. It is what you consider under option (b).

Here is my typedoc.json config: https://github.com/theemo-tokens/theemo/blob/ad8dfc66f0d61e0209e59ff0498492cd27b23f0e/typedoc.json

Also the repo at the time of writing: https://github.com/theemo-tokens/theemo/tree/ad8dfc66f0d61e0209e59ff0498492cd27b23f0e

Not sure if pointing to the root of vitepress is helpful, e.g. if this is two folders deep, would it work? So probably something along the lines of <base href=""> is the proper mental model?

tgreyuk commented 10 months ago

@gossi thanks.

I have been exploring a few options here. The issue is that the sidebar links need to be from the VitePress root and we have no context of this at the time of publishing. All other links are relative so there is no problem outside of the sidebar.

Solutions:

a) Attempted to resolve this programatically from exploring the file system for a folder named .vitepress. This works but feels a bit brittle.

b) Expose an additional option docsRoot that is the path to the VitePress project root which defaults to ./.

c) Expose a new option exposed to the sidebar sidebar.basePath which I think conceptually works best (its not published yet but just floating my idea):

Let me know if you think this makes sense.

gossi commented 10 months ago

I like that, sounds very good. Option (b) and (c) are both fine, no preference from my side.

tgreyuk commented 10 months ago

Went for docsRoot option in the end which is in "typedoc-vitepress-theme": "^1.0.0-next.7".

So you could just do the following and remove the mv script.

"out": "./docs/api",
"docsRoot": "./docs",

https://www.typedoc-plugin-markdown.org/themes/vitepress/options#docsroot

maximesimoncelli commented 10 months ago

Hello, had the same problem as @gossi, just tested the -next.7 release and it works perfectly, thanks !

gossi commented 10 months ago

Absolutely fantastic, I love it 👍 Thank you so much 🙇

Happily closing this one.