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

fix: Adjust markdown links to correct level #255

Merged
merged 2 commits into from
Jul 19, 2024
Merged

fix: Adjust markdown links to correct level #255

merged 2 commits into from
Jul 19, 2024

Conversation

lachlancollins
Copy link
Member

@lachlancollins lachlancollins commented Jul 18, 2024

Problem

Currently, markdown links are written in a way that is compatible with tanstack.com, but not with native markdown navigation.

For example: https://github.com/TanStack/query/blob/13817e953743537ffb9aab4da174583055be4d81/docs/framework/react/overview.md?plain=1#L99

Clicking either of these links will fail if you navigate on GitHub or in your IDE.

Solution

If we write the docs using correct markdown links, we can use regex on tanstack.com to correct the path:

const relativeHref = props.href?.replace(/([A-Za-z][A-Za-z/_-]+).md/, '../$1')
  • ([A-Za-z][A-Za-z/_-]+) matches group 1 starting with a letter, then optionally also containing /, - or _
  • .md matches the markdown extension outside the group (existing links will NOT break as they do not have .md)
  • ../$1 prefixes group 1 with ../

For example, this rewrites reference/FormApi.md to ../reference/FormApi

This even works for something like ./reference/FormApi.md, which gets rewritten to ./../reference/FormApi but still correctly routes on tanstack.com.

Copy link

vercel bot commented Jul 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tanstack-com ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 19, 2024 6:19am

@lachlancollins
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants