Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/busy-walls-enter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@alauda/doom": patch
---

chore(deps): bump rspress to v2.0.0-beta.30
12 changes: 6 additions & 6 deletions packages/doom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
],
"dependencies": {
"@alauda/doom-export": "^0.1.0",
"@cspell/eslint-plugin": "^8.19.4 || ^9.2.0",
"@cspell/eslint-plugin": "^8.19.4 || ^9.2.1",
"@eslint-react/eslint-plugin": "^1.52.9",
"@inquirer/prompts": "^7.8.4",
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
Expand All @@ -50,11 +50,11 @@
"@rsbuild/plugin-sass": "^1.4.0",
"@rsbuild/plugin-svgr": "^1.2.2",
"@rsbuild/plugin-yaml": "^1.0.3",
"@rspress/core": "2.0.0-beta.29",
"@rspress/plugin-algolia": "2.0.0-beta.29",
"@rspress/plugin-llms": "2.0.0-beta.29",
"@rspress/plugin-sitemap": "2.0.0-beta.29",
"@rspress/shared": "2.0.0-beta.29",
"@rspress/core": "2.0.0-beta.30",
"@rspress/plugin-algolia": "2.0.0-beta.30",
"@rspress/plugin-llms": "2.0.0-beta.30",
"@rspress/plugin-sitemap": "2.0.0-beta.30",
"@rspress/shared": "2.0.0-beta.30",
"@shikijs/transformers": "^3.12.1",
"@total-typescript/ts-reset": "^0.6.1",
"ab64": "^0.1.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/doom/src/cli/load-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { pluginSitemap } from '@rspress/plugin-sitemap'
import {
addLeadingSlash,
addTrailingSlash,
normalizeSlash,
removeLeadingSlash,
type LocaleConfig,
} from '@rspress/shared'
Expand Down Expand Up @@ -46,6 +45,7 @@ import {
} from '../plugins/index.js'
import {
isExplicitlyUnversioned,
normalizeSlash,
UNVERSIONED,
type DoomSite,
} from '../shared/index.js'
Expand Down
9 changes: 8 additions & 1 deletion packages/doom/src/shared/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { NavItemWithLink } from '@rspress/core'
import { addLeadingSlash, normalizeSlash } from '@rspress/shared'
import {
addLeadingSlash,
normalizePosixPath,
removeTrailingSlash,
} from '@rspress/shared'

import { UNVERSIONED, UNVERSIONED_PREFIX } from './constants.ts'
import type { UnversionedVersion } from './types.ts'
Expand Down Expand Up @@ -42,6 +46,9 @@ export const extractTextAndId = (title: string) => {
]
}

export const normalizeSlash = (url: string) =>
removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)))

export const withoutBase = (path: string, base: string) =>
addLeadingSlash(path).replace(normalizeSlash(base), '')

Comment on lines +49 to 54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Harden normalizeSlash and anchor withoutBase to avoid false matches.

  • Root path edge case: current impl can turn "/" into "", depending on removeTrailingSlash semantics.
  • withoutBase may strip matches in the middle of the path (e.g., "/docs" removed from "/foo/docs") instead of only from the start.

Apply:

-export const normalizeSlash = (url: string) =>
-  removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)))
+export const normalizeSlash = (url: string) => {
+  const p = addLeadingSlash(normalizePosixPath(url))
+  // Keep "/" intact; only trim trailing slash when length > 1
+  return p.length > 1 ? removeTrailingSlash(p) : p
+}

-export const withoutBase = (path: string, base: string) =>
-  addLeadingSlash(path).replace(normalizeSlash(base), '')
+export const withoutBase = (path: string, base: string) => {
+  const p = addLeadingSlash(path)
+  const b = normalizeSlash(base)
+  return p.startsWith(b) ? p.slice(b.length) : p
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const normalizeSlash = (url: string) =>
removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)))
export const withoutBase = (path: string, base: string) =>
addLeadingSlash(path).replace(normalizeSlash(base), '')
export const normalizeSlash = (url: string) => {
const p = addLeadingSlash(normalizePosixPath(url))
// Keep "/" intact; only trim trailing slash when length > 1
return p.length > 1 ? removeTrailingSlash(p) : p
}
export const withoutBase = (path: string, base: string) => {
const p = addLeadingSlash(path)
const b = normalizeSlash(base)
return p.startsWith(b) ? p.slice(b.length) : p
}
🤖 Prompt for AI Agents
In packages/doom/src/shared/helpers.ts around lines 49 to 54, normalizeSlash can
collapse the root "/" to an empty string and withoutBase can remove the base
anywhere in the path; update normalizeSlash to always return "/" for the root
path after normalization (i.e., treat empty result as "/") and ensure
withoutBase only strips the normalized base when it appears at the start of the
path (anchor the match) by normalizing both inputs, ensuring leading slashes,
and using a startsWith check or a anchored replacement (not a global replace) so
occurrences in the middle of the path are not removed.

Expand Down
Loading
Loading