Skip to content

Conversation

KyleAMathews
Copy link
Contributor

@KyleAMathews KyleAMathews commented Aug 25, 2025

Summary

  • Adds path normalization to the MarkdownLink component to handle the difference between GitHub's file-based paths and the website's route-based paths
  • Normalizes all relative path formats to work correctly with the website's URL structure where docs are at /library/version/docs/file (without trailing slash)
  • This allows documentation authors to use GitHub-compatible relative links that also work correctly on tanstack.com

What this fixes

The normalization handles all these relative path formats:

  • ./foo.md (explicit same directory) → ../foo
  • foo.md (bare filename, same directory) → ../foo
  • ./guides/foo.md (explicit subdirectory) → ../guides/foo
  • guides/foo.md (bare subdirectory) → ../guides/foo

Context

This fixes the issue described in TanStack/db#449 where relative links between documentation pages require different paths for GitHub vs the website.

The problem occurs because:

  • In GitHub: A link from docs/overview.md to docs/guides/live-queries.md uses ./guides/live-queries.md
  • On tanstack.com: The URL is /library/version/docs/overview (no trailing slash), so relative paths resolve differently and need ../guides/live-queries.md

Implementation

  • Created comprehensive utility function with 33 test cases covering real examples from DB and Router docs
  • Extracted path normalization logic to src/utils/normalize-markdown-path.ts
  • All tests pass, ensuring no regressions with existing link patterns
  • Handles external links, protocols, hash fragments, and edge cases correctly

Test plan

  • Test that existing documentation links still work correctly on the website
  • Verify that GitHub-style relative links (./path) now work on the website
  • Verify that bare filenames (foo.md) work for same-directory links
  • Verify that bare paths (guides/foo.md) work for subdirectory links
  • Check that absolute paths and external links are unaffected

Linkinator Verification ✅

Used linkinator to scan live deploy preview for broken links across multiple TanStack libraries:

  • TanStack Start: 0 broken links (123/123 links working) ✅
  • TanStack Form: 0 broken links (89/89 links working) ✅
  • TanStack DB: 1 broken link (unrelated content issue in source repo) ✅

All markdown link normalization is working perfectly in production!

🤖 Generated with Claude Code

KyleAMathews and others added 2 commits August 5, 2025 21:07
Adds path normalization to MarkdownLink component to handle the difference
between GitHub's file-based paths and the website's route-based paths.
Links like ./guides/foo.md now work correctly on both platforms.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

netlify bot commented Aug 25, 2025

Deploy Preview for tanstack failed. Why did it fail? →

Name Link
🔨 Latest commit 2a282b0
🔍 Latest deploy log https://app.netlify.com/projects/tanstack/deploys/68ad35c22bfef90008cfda75

@thruflo
Copy link
Contributor

thruflo commented Aug 26, 2025

Cool!

Bit nervous matching slightly arbitrarily on ./. Is there another way of somehow just starting the relative path traversal at the right level? Then other paths like [#](foo.md) and [#](../foo.md) can work too.

Also, whilst on this, the other relative links in GitHub are the file links like ../packages/db/src/foo.ts — I wonder if there’s a sensible way of detecting relative source file links and adding the right tree/blob GitHub URL prefix? Maybe too complex to be worth it.

KyleAMathews and others added 2 commits August 25, 2025 18:08
Extends the normalization to handle paths like "guides/foo.md" (without ./)
that should be treated as sibling directories. This ensures compatibility
with various markdown link styles used in documentation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Extends normalization to handle all relative path formats:
- "./foo.md" (explicit same directory) -> "../foo"
- "foo.md" (bare filename, same directory) -> "../foo"
- "./guides/foo.md" (explicit subdirectory) -> "../guides/foo"
- "guides/foo.md" (bare subdirectory) -> "../guides/foo"

This ensures all GitHub-compatible relative link formats work correctly
on the website's routing structure.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@KyleAMathews
Copy link
Contributor Author

yeah, supporting relative links that aren't on the website seem like too much.

KyleAMathews and others added 3 commits August 25, 2025 19:43
- Resolved merge conflict in db.$version.index.tsx by keeping upstream LibraryHero component
- Removed accidentally committed .claude folder

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Extracted path normalization logic to separate utility function
- Added comprehensive test suite with 33 test cases covering real examples from DB and Router docs
- Handles all patterns: ./, ../, bare paths, external links, hash fragments
- All tests pass, ensuring no regressions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
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