-
Notifications
You must be signed in to change notification settings - Fork 10
feat: try change output structure #455
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
WalkthroughA new post-prerendering process was introduced for the blog application. This includes a new Nx target and script that renames Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant NPM Script
participant Nx
participant Build Routes
participant Build
participant Post-Prerender Script
User->>NPM Script: Run `npm run prerender`
NPM Script->>Nx: Execute blog:build-routes
Nx->>Build Routes: Build routes
Build Routes-->>Nx: Done
Nx->>Nx: Execute blog:build
Nx->>Build: Build blog
Build-->>Nx: Done
Nx->>Nx: Execute blog:post-prerender
Nx->>Post-Prerender Script: Run post-prerender.mjs
Post-Prerender Script-->>Nx: Rename files
Nx-->>NPM Script: Done
NPM Script-->>User: Prerender complete
Poem
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
PR is detected, will deploy to dev environment |
Deployed to dev environment |
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.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
apps/blog/project.json
(1 hunks)apps/blog/scripts/post-prerender.mjs
(1 hunks)package.json
(1 hunks)
🔇 Additional comments (4)
apps/blog/project.json (1)
109-114
: LGTM! Well-structured Nx target configuration.The new
post-prerender
target is correctly configured using thenx:run-commands
executor and follows the same pattern as the existingbuild-routes
target.package.json (1)
19-19
: LGTM! Logical sequence for the prerendering workflow.The updated script correctly chains the build process: route building → application building → post-processing. This ensures the post-prerender step runs after all necessary files are generated.
apps/blog/scripts/post-prerender.mjs (2)
1-5
: LGTM! Appropriate imports and well-defined constants.The imports are correct for the file operations, and the skip folders list appropriately excludes asset directories from processing.
42-48
: LGTM! Appropriate error handling for a build script.The top-level error handling with
process.exit(1)
ensures build failures are properly communicated, and immediate script execution is appropriate for this use case.
const indexPath = join(currentDirPath, 'index.html'); | ||
|
||
try { | ||
await rename(indexPath, join(currentDirPath, `${entry.name}.html`)); | ||
console.log(`Renamed ${indexPath} to ${entry.name}.html`); | ||
} catch (error) { | ||
if (error.code !== 'ENOENT') { | ||
console.error(`Error processing ${currentDirPath}:`, error); | ||
} | ||
} |
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.
Validate filename before renaming to prevent incorrect file operations.
The script assumes that if there's exactly one file, it must be index.html
, but this isn't validated. This could lead to renaming wrong files.
Add filename validation:
- const indexPath = join(currentDirPath, 'index.html');
-
- try {
- await rename(indexPath, join(currentDirPath, `${entry.name}.html`));
- console.log(`Renamed ${indexPath} to ${entry.name}.html`);
- } catch (error) {
- if (error.code !== 'ENOENT') {
- console.error(`Error processing ${currentDirPath}:`, error);
- }
- }
+ const singleFile = files[0];
+ if (singleFile !== 'index.html') {
+ console.warn(`Skipping ${currentDirPath} - single file is not index.html: ${singleFile}`);
+ continue;
+ }
+
+ const indexPath = join(currentDirPath, 'index.html');
+ const newPath = join(currentDirPath, `${entry.name}.html`);
+
+ try {
+ await rename(indexPath, newPath);
+ console.log(`Renamed ${indexPath} to ${entry.name}.html`);
+ } catch (error) {
+ console.error(`Error renaming ${indexPath}:`, error);
+ }
📝 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.
const indexPath = join(currentDirPath, 'index.html'); | |
try { | |
await rename(indexPath, join(currentDirPath, `${entry.name}.html`)); | |
console.log(`Renamed ${indexPath} to ${entry.name}.html`); | |
} catch (error) { | |
if (error.code !== 'ENOENT') { | |
console.error(`Error processing ${currentDirPath}:`, error); | |
} | |
} | |
const singleFile = files[0]; | |
if (singleFile !== 'index.html') { | |
console.warn(`Skipping ${currentDirPath} - single file is not index.html: ${singleFile}`); | |
continue; | |
} | |
const indexPath = join(currentDirPath, 'index.html'); | |
const newPath = join(currentDirPath, `${entry.name}.html`); | |
try { | |
await rename(indexPath, newPath); | |
console.log(`Renamed ${indexPath} to ${entry.name}.html`); | |
} catch (error) { | |
console.error(`Error renaming ${indexPath}:`, error); | |
} |
🤖 Prompt for AI Agents
In apps/blog/scripts/post-prerender.mjs around lines 30 to 39, the code renames
a file assuming it is named index.html without validating the filename. To fix
this, add a check to confirm that the file to be renamed is actually named
index.html before attempting the rename operation. If the filename does not
match, skip the rename or handle the case appropriately to avoid incorrect file
operations.
if (files.length > 1) { | ||
console.error(`Multiple files in ${currentDirPath}:`, files); | ||
await renamePrerenderedFiles(currentDirPath); | ||
continue; | ||
} |
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.
Fix inconsistent logic for directories with multiple files.
When multiple files are found in a directory, the script logs an error but then recurses into the same directory. This creates inconsistent behavior - if multiple files indicate an error condition, the directory should be skipped rather than processed recursively.
Consider this approach:
- if (files.length > 1) {
- console.error(`Multiple files in ${currentDirPath}:`, files);
- await renamePrerenderedFiles(currentDirPath);
- continue;
- }
+ if (files.length > 1) {
+ console.warn(`Skipping ${currentDirPath} - contains multiple files:`, files);
+ // Only recurse if this directory might contain subdirectories to process
+ await renamePrerenderedFiles(currentDirPath);
+ continue;
+ }
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In apps/blog/scripts/post-prerender.mjs around lines 24 to 28, the code logs an
error when multiple files are found in a directory but then continues processing
that directory recursively, causing inconsistent behavior. Modify the logic so
that when multiple files are detected, the directory is skipped entirely instead
of recursing into it. Remove or adjust the call to renamePrerenderedFiles and
the continue statement to prevent further processing of that directory.
PR is detected, will deploy to dev environment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/blog/src/_redirects (1)
145-287
: Consider redundancy with the catch-all trailing slash rule.These explicit trailing slash redirects work correctly but may be redundant given the universal trailing slash removal rule at line 303. However, keeping explicit rules for known URLs could be intentional for performance optimization.
If performance isn't a concern, you could potentially remove lines 145-287 and rely solely on the catch-all rule at line 303 to handle trailing slash removal for these URLs.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/blog/src/_redirects
(1 hunks)
🔇 Additional comments (4)
apps/blog/src/_redirects (4)
1-143
: LGTM! Polish article redirects are correctly structured.The redirects properly add the
/pl/
language prefix to Polish articles and correctly omit trailing slashes from target URLs, aligning with the URL normalization strategy.
290-297
: LGTM! Date-based URL migration is properly implemented.The redirects correctly migrate from date-based URL structure to simplified language-prefixed paths, handling both English and Polish articles with proper trailing slash normalization.
299-301
: Verify the broad English catch-all redirect behavior.The English catch-all rule
/en/* /:splat 301
redirects any English path to the root. This might be overly broad if there are legitimate English pages that should remain accessible.Please confirm this is the intended behavior - should ALL English paths (except those with specific rules above) redirect to the root, or are there English pages that should remain accessible?
303-303
: LGTM! Universal trailing slash removal is correctly implemented.The catch-all rule properly removes trailing slashes from any URL using the
:splat
parameter, ensuring consistent URL normalization across the site.
Deployed to dev environment |
Summary by CodeRabbit
New Features
Chores