Skip to content

Feat/url id query and type module#767

Merged
yangxiaolang merged 3 commits into
mainfrom
feat/url-id-query-and-type-module
May 25, 2026
Merged

Feat/url id query and type module#767
yangxiaolang merged 3 commits into
mainfrom
feat/url-id-query-and-type-module

Conversation

@yangxiaolang
Copy link
Copy Markdown
Collaborator

@yangxiaolang yangxiaolang commented May 25, 2026

Summary by CodeRabbit

  • New Features

    • Added support for post ID-based routing with automatic locale matching—users can now navigate to posts using a query parameter.
  • Chores

    • Migrated project to ES modules (ESM) with explicit module paths for improved compatibility.
    • Enhanced path resolution for ES module context.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 25, 2026

Walkthrough

This PR systematically converts the project from CommonJS and inconsistent module patterns to strict ES modules (ESM). It adds "type": "module" to package.json, converts config files to ESM syntax, updates all module imports with explicit .js extensions throughout plugins and theme files, and introduces post ID query parameter redirection in the layout component with locale-aware post lookup.

Changes

ES Module System Conversion and Post ID Redirection

Layer / File(s) Summary
ESM Module Type Declaration
package.json
Root-level declaration of "type": "module" to enable ES module interpretation for all package files.
Configuration File ESM Conversion
doom.config.ts, postcss.config.js
Build and PostCSS configs converted from CommonJS or inconsistent patterns to ESM; doom.config.ts adds __dirname computation for ESM-safe path resolution.
Plugin Module ESM Standardization
plugins/plugin-post-resolver/BlogPostResolver.ts, plugins/plugin-post-resolver/PostData.ts, plugins/plugin-post-resolver/index.ts
Plugin modules updated with type-only imports for TypeScript types and explicit .js extensions for all local module imports.
Theme Infrastructure and Layout Imports
theme/index.tsx, theme/layout/DocLayout/index.tsx, theme/layout/HomeLayout/index.tsx
Theme index and layout files updated to use explicit .js-suffixed paths for internal component and layout imports while preserving public export surfaces.
Theme Component Imports
theme/components/HomeContent/index.tsx, theme/components/PostList/index.tsx, theme/components/SidebarMenu/index.ts
Individual theme components updated to use .js-suffixed paths; PostInfo in PostList converted to type-only import.
Post ID Redirection Feature
theme/layout/index.tsx
Adds postInfos import and implements post ID query parameter redirection: normalizes the ?id= query param, finds matching post (locale-aware), redirects to matched route with .html suffix while removing the id param, and posts resulting URL to parent window.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 From CommonJS paths to modules so bright,
The .js extensions now guide every light,
With "type": "module" the package takes flight,
And posts find their routes with locale's insight,
A cohesive migration—ESM done right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title references both main changes: URL ID query parameter handling and TypeScript module conversion to ESM, though it uses shorthand notation ('type module' for 'TypeScript/ESM modules').
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/url-id-query-and-type-module

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@theme/layout/index.tsx`:
- Around line 71-80: The current matching logic for normalizedPostId can return
a post from any locale because the fallback postInfos.find(...) ignores
page.lang; change this by first collecting candidates where
normalizePostId(post.id) === normalizedPostId, then set matchedPost to the
candidate that also matches page.lang if present, otherwise only use the single
candidate when candidates.length === 1; update the code around normalizedPostId
/ matchedPost / postInfos / normalizePostId to implement this
conditional-fallback behavior so you never redirect to an arbitrary locale when
multiple candidates exist.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4248c345-f45a-4132-8976-2cb4aa7b9792

📥 Commits

Reviewing files that changed from the base of the PR and between dd0a5fd and 988fbc4.

📒 Files selected for processing (13)
  • doom.config.ts
  • package.json
  • plugins/plugin-post-resolver/BlogPostResolver.ts
  • plugins/plugin-post-resolver/PostData.ts
  • plugins/plugin-post-resolver/index.ts
  • postcss.config.js
  • theme/components/HomeContent/index.tsx
  • theme/components/PostList/index.tsx
  • theme/components/SidebarMenu/index.ts
  • theme/index.tsx
  • theme/layout/DocLayout/index.tsx
  • theme/layout/HomeLayout/index.tsx
  • theme/layout/index.tsx

Comment thread theme/layout/index.tsx
Comment on lines +71 to +80
if (normalizedPostId) {
const matchedPost =
postInfos.find(
(post) =>
normalizePostId(post.id) === normalizedPostId &&
post.locale === page.lang
) ||
postInfos.find(
(post) => normalizePostId(post.id) === normalizedPostId
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid redirecting to an arbitrary locale on fallback.

If the same id exists in multiple locales, the second find() ignores page.lang and can send users to the wrong language variant. A safer fallback is to ignore locale only when there is exactly one candidate for that id.

Suggested fix
-    if (normalizedPostId) {
-      const matchedPost =
-        postInfos.find(
-          (post) =>
-            normalizePostId(post.id) === normalizedPostId &&
-            post.locale === page.lang
-        ) ||
-        postInfos.find(
-          (post) => normalizePostId(post.id) === normalizedPostId
-        );
+    if (normalizedPostId) {
+      const candidates = postInfos.filter(
+        (post) => normalizePostId(post.id) === normalizedPostId
+      );
+      const matchedPost =
+        candidates.find((post) => post.locale === page.lang) ??
+        (candidates.length === 1 ? candidates[0] : undefined);
📝 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
if (normalizedPostId) {
const matchedPost =
postInfos.find(
(post) =>
normalizePostId(post.id) === normalizedPostId &&
post.locale === page.lang
) ||
postInfos.find(
(post) => normalizePostId(post.id) === normalizedPostId
);
if (normalizedPostId) {
const candidates = postInfos.filter(
(post) => normalizePostId(post.id) === normalizedPostId
);
const matchedPost =
candidates.find((post) => post.locale === page.lang) ??
(candidates.length === 1 ? candidates[0] : undefined);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@theme/layout/index.tsx` around lines 71 - 80, The current matching logic for
normalizedPostId can return a post from any locale because the fallback
postInfos.find(...) ignores page.lang; change this by first collecting
candidates where normalizePostId(post.id) === normalizedPostId, then set
matchedPost to the candidate that also matches page.lang if present, otherwise
only use the single candidate when candidates.length === 1; update the code
around normalizedPostId / matchedPost / postInfos / normalizePostId to implement
this conditional-fallback behavior so you never redirect to an arbitrary locale
when multiple candidates exist.

@yangxiaolang yangxiaolang merged commit da3a5ae into main May 25, 2026
2 checks passed
@yangxiaolang yangxiaolang deleted the feat/url-id-query-and-type-module branch May 25, 2026 07:35
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.

1 participant