-
-
Notifications
You must be signed in to change notification settings - Fork 205
chore(core): expose routePathToMdPath utility in runtime #2967
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
Conversation
…function in `@rspress/core/runtime` by moving it to `packages/core/src/runtime/utils.ts`, updating the implementation with the requested logic, and exporting it. I also updated `packages/core/src/theme/components/Overview/index.tsx` to use the exposed function. Finally, I verified the changes by building the package and creating a unit test `packages/core/src/runtime/utils.test.ts` which covers various scenarios. **Summary of changes:** 1. **Modified `packages/core/src/runtime/utils.ts`**: Added `routePathToMdPath` with the improved logic `url.replace(/\.html(?=#|\?|$)/, '.md')` and exported it. 2. **Modified `packages/core/src/runtime/index.ts`**: Exported `routePathToMdPath` from `utils`. 3. **Modified `packages/core/src/theme/components/Overview/index.tsx`**: Removed local implementation and imported `routePathToMdPath` from `@rspress/core/runtime`. Removed unused imports (`normalizeHref`, `withBase`). 4. **Created `packages/core/src/runtime/utils.test.ts`**: Added unit tests to verify the logic. Verified with `pnpm build` in `packages/core` and `pnpm rstest run packages/core/src/runtime/utils.test.ts`.
…s with hashes and query parameters. The tests use `matchInlineSnapshot` and I've verified the snapshots are correctly generated and the logic holds up. **Summary of changes:** 1. Modified `packages/core/src/runtime/utils.test.ts` to include a comprehensive list of test cases (hash, query, combinations). 2. Updated the test to use `toMatchInlineSnapshot`. 3. Executed `npx rstest` to generate the correct snapshots. The `routePathToMdPath` function is now well-tested and verified.
✅ Deploy Preview for rspress-v2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the routePathToMdPath utility function by moving it from the Overview component to the runtime utils module, making it available for reuse across the codebase. The refactoring also includes an improvement to the regex pattern for handling query strings and hash fragments.
Key Changes:
- Moved
routePathToMdPathfunction from Overview component to@rspress/core/runtimeutils - Improved regex pattern from
/\.html$/to/\.html(?=#|\?|$)/to correctly handle URLs with query strings and hash fragments - Added comprehensive test coverage with snapshot testing for various URL formats
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/core/src/theme/components/Overview/index.tsx | Removed local routePathToMdPath implementation and imports for normalizeHref and withBase; now imports the function from runtime |
| packages/core/src/runtime/utils.ts | Added routePathToMdPath function implementation with improved regex pattern and exported it |
| packages/core/src/runtime/utils.test.ts | Added new test file with comprehensive test cases covering various URL formats including paths with hashes, query strings, and combinations |
| packages/core/src/runtime/index.ts | Exported routePathToMdPath function to make it publicly available in the runtime API |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rsdoctor Bundle Diff AnalysisFound 3 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
Description
This PR moves the
routePathToMdPathutility function from theOverviewtheme component to the core runtime utilities (@rspress/core/runtime).Changes
routePathToMdPathlogic topackages/core/src/runtime/utils.tsand exported it viapackages/core/src/runtime/index.ts./\.html(?=#|\?|$)/) to correctly handle URLs with hashes and query parameters when replacing extensions.packages/core/src/theme/components/Overview/index.tsxto use the exposed utility and removed the local implementation.packages/core/src/runtime/utils.test.tsto ensure correct behavior across various URL formats.This PR was written using Vibe Kanban