Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a way to link to category generated-index #6041

Open
1 of 2 tasks
slorber opened this issue Dec 3, 2021 · 6 comments
Open
1 of 2 tasks

Find a way to link to category generated-index #6041

slorber opened this issue Dec 3, 2021 · 6 comments
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@slorber
Copy link
Collaborator

slorber commented Dec 3, 2021

Have you read the Contributing Guidelines on issues?

Motivation

For docs, we recommend using relative file paths:

For our new category index feature, there is no .md file to link to so we must use regular links.

Problem:

  • Using an absolute link would not play well with versioning: [Guides](/docs/next/category/guides).
  • Using a relative link would not play well with changing the trailingSlash setting: [Guides](./category/guides).

This is particularly annoying for our own website, as we use different settings for dogfooding on dev/deployPreview/prod. It is not easy to find a good workaround so that our site could be deployed on every env without reporting broken links 😅 (see workaround ac44531)

It may be annoying for our users too.

We should probably find a way to link more easily to a category, but not sure how this should be done 🤷‍♂️

Self-service

  • I'd be willing to do some initial work on this proposal myself.
@slorber slorber added proposal This issue is a proposal, usually non-trivial change status: needs triage This issue has not been triaged by maintainers labels Dec 3, 2021
@Josh-Cena Josh-Cena added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. and removed proposal This issue is a proposal, usually non-trivial change status: needs triage This issue has not been triaged by maintainers labels Dec 3, 2021
@Josh-Cena
Copy link
Collaborator

What about a new useVersionedLink API?

Firstly, I don't think generated category indexes will be linked to very often anyways, so we probably don't need special sugar for this.

Then, the issue is only about how we can programmatically get the link to a doc plugin route, versioned. We have a similar need when we implemented the remark plugin to generate our API documentation: the link currently always links to the current version because the remark plugin is unaware of the version context.

My idea is just a useVersionedLink(url: string, pluginId?: string): string that returns /docs/2.0.0-beta.13/installation from installation. This way, we can do the same thing for all links:

// The plugin baseUrl & version baseUrl will both be prepended
<a href={useVersionedLink('/category/guides')}>Guides</a>

@slorber
Copy link
Collaborator Author

slorber commented Jan 5, 2022

Firstly, I don't think generated category indexes will be linked to very often anyways, so we probably don't need special sugar for this.

🤷‍♂️ I don't know, this makes sense to me to link to them and we already had the case for our own website. We'll see as category indexes grow in usage, for now relative links can be good enough for most users.


useVersionedLink is something related to docs only, and can't really be in core.

Also, I'm not sure we want to require users to use MDX/hooks to handle this use case inside markdown files.


Maybe we could have a docs-only remark plugin and allow to just write [Guides](/category/guides)

If we know that /docs/version/category/guides exist, we rewrite to that absolute path?

🤷‍♂️ that seems quite intuitive to me, but we can as well have a new protocol: [Guides](docs:///category/guides)


Also, I'd find it interesting if our Link was a theme component. This would allow users to implement their own linking specific behaviors at runtime.

@Josh-Cena
Copy link
Collaborator

useVersionedLink is something related to docs only, and can't really be in core.

Our docs plugin exports a lot of version-related hooks. This one is no special.

Maybe we could have a docs-only remark plugin and allow to just write [Guides](/category/guides)

We do have a linkifier that transforms file paths to URLs. Maybe we can just use a sugar to indicate category indexes? (like docs:///category/guides but overall I don't like these magic protocols and would just go for an artificial syntax like *category*/guides. Still a bad example but that's the point)

@slorber
Copy link
Collaborator Author

slorber commented Jan 5, 2022

Our docs plugin exports a lot of version-related hooks. This one is no special.

Exposed in a not very elegant way BTW, not sure theming is the best for that. Maybe we should find a better solution like exposing these with https://nodejs.org/api/packages.html#package-entry-points

Note those hooks are not publicly documented for the moment (neither is global data).

The one you are suggesting is meant to be used by end-users so it's not exactly the same.


I don't like magic protocols either but I don't really know how else to do without this.

We also should think about users that will want to opt-out of MDX, and offer them a way to link to category index using plain MD GFM syntax

@yoavniran
Copy link

For Uploady's doc site I wanted to link from navbar to an auto-generated category index and realized it wasn't possible. 😢

Luckily, found this issue and the useful comment along with docs explaining how to work around the limitation.

But it definitely feels messy and over-doing something that should have been builtin and declarative.

Sorry if too simplistic, but I was just expecting to have the option to specify a doc ID (in my sidebars.js) to the auto-generated index that I could link to.

@gimmebytes
Copy link

I just started out using docusaurus for an internal documentation hub and stumbled over the exact same issue. While writing the outline, I will just use hardcoded links (yikes) but, it would be awesome to just reference docs from the generated index via md, without any magic tricks, as @yoavniran mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
Development

No branches or pull requests

4 participants