-
Notifications
You must be signed in to change notification settings - Fork 264
Improve redirect link automation #1437
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
✅ Deploy Preview for docs-optimism ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
📝 WalkthroughWalkthroughThis pull request refines both the documentation and the implementation of the Sequence Diagram(s)sequenceDiagram
participant User as User
participant Script as fix-redirects Script
participant FS as File System
participant Log as Logger
User->>Script: Execute fix-redirects script
Script->>FS: Read _redirects file
FS-->>Script: Return redirects data or error
alt Redirects file is available
Script->>FS: List Markdown/HTML files in the target directory
loop For each file
Script->>FS: Read file content
alt File read successfully
Script->>Script: Process content to identify outdated links (via regex)
alt Outdated links found
Script->>FS: Write updated file content
else
Script->>Script: Mark file as unchanged
end
else
Script->>Log: Log file read error
end
end
Script->>Log: Log summary report of changes
else
Script->>Log: Log error reading _redirects file and exit
end
Possibly related PRs
Suggested reviewers
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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
Documentation and Community
|
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)
notes/fix-redirects.md (1)
91-92
: Added helpful troubleshooting information.The added points about no outdated links being found and the script's limitation regarding destination URL verification provide valuable troubleshooting information for users.
You might want to ensure the list formatting is consistent by adding a space after the asterisk, as with other list items in the document:
-* No outdated links found: Verify `_redirects` entries are correct or all links might already be updated. -* Links still broken after fixing: The script only updates links based on the `_redirects` file; it doesn't check if the destination URLs actually exist. +* No outdated links found: Verify `_redirects` entries are correct or all links might already be updated. +* Links still broken after fixing: The script only updates links based on the `_redirects` file; it doesn't check if the destination URLs actually exist.🧰 Tools
🪛 LanguageTool
[uncategorized] ~91-~91: Use a comma before “or” if it connects two independent clauses (unless they are closely connected and short).
Context: ... Verify_redirects
entries are correct or all links might already be updated. * ...(COMMA_COMPOUND_SENTENCE_2)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
notes/fix-redirects.md
(3 hunks)utils/fix-redirects.ts
(3 hunks)utils/redirects.ts
(2 hunks)
🧰 Additional context used
🪛 LanguageTool
notes/fix-redirects.md
[uncategorized] ~6-~6: Loose punctuation mark.
Context: ...s are redirected: * check-redirects
: Identifies links that point to old URLs...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~7-~7: Loose punctuation mark.
Context: ...e _redirects
file. * fix-redirects
: Automatically updates links to use the ...
(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~91-~91: Use a comma before “or” if it connects two independent clauses (unless they are closely connected and short).
Context: ... Verify _redirects
entries are correct or all links might already be updated. * ...
(COMMA_COMPOUND_SENTENCE_2)
🪛 markdownlint-cli2 (0.17.2)
notes/fix-redirects.md
60-60: Multiple headings with the same content
null
(MD024, no-duplicate-heading)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Redirect rules - docs-optimism
- GitHub Check: Header rules - docs-optimism
- GitHub Check: Pages changed - docs-optimism
🔇 Additional comments (32)
utils/redirects.ts (11)
1-2
: Improved script identification and clarity!Adding a shebang line and descriptive comment enhances script identification and usability, allowing direct execution and clarifying the file's purpose.
18-21
: Improved interface formatting.The reformatting of the Redirect interface improves code readability while maintaining the same functionality.
23-27
: Improved interface formatting.The reformatting of the Summary interface improves code readability while maintaining the same functionality.
30-30
: Better terminology in warning messages.Changing "broken link" to "outdated link" in the warning message is more accurate, as these links aren't broken but pointing to old URLs that have redirects.
33-46
: Enhanced error handling in getRedirects function.Adding try-catch error handling for file operations is an excellent improvement. This prevents the script from crashing when the redirects file can't be read and provides a meaningful error message.
48-67
: Enhanced error handling in findMdxFiles function.The addition of try-catch error handling for directory operations is a valuable improvement. This ensures the script continues execution even if a directory can't be accessed, logging the error instead of crashing.
88-103
: Enhanced error handling in checkFile function.Adding try-catch error handling for file operations in the checkFile function improves robustness. This ensures that errors during file checking are properly logged without stopping the entire process.
107-110
: Improved summary output terminology.Changing "files" to "pages" and "broken links" to "outdated links" in the summary output provides more accurate and consistent terminology throughout the application.
122-138
: Added essential directory and file existence checks.Adding explicit checks for the existence of the root directory and redirects file before proceeding is an excellent improvement. This prevents cryptic errors later in the process and provides clear error messages about missing prerequisites.
151-155
: Improved error counting logic.The modification to count files with errors rather than total warnings is a better approach. This provides a more meaningful summary by focusing on the number of pages that need attention rather than the total number of individual links.
171-175
: Enhanced error handling for script execution.Adding explicit script execution with proper error handling ensures that any uncaught errors during the main process execution are properly logged and result in an appropriate exit code.
notes/fix-redirects.md (9)
6-7
: Clearer script descriptions.The updated descriptions provide better clarity about what each script does, specifically mentioning their relationship with the
_redirects
file.🧰 Tools
🪛 LanguageTool
[uncategorized] ~6-~6: Loose punctuation mark.
Context: ...s are redirected: *check-redirects
: Identifies links that point to old URLs...(UNLIKELY_OPENING_PUNCTUATION)
[uncategorized] ~7-~7: Loose punctuation mark.
Context: ...e_redirects
file. *fix-redirects
: Automatically updates links to use the ...(UNLIKELY_OPENING_PUNCTUATION)
9-9
: Better terminology in section title.Changing "broken links" to "outdated links" in the section title is more accurate and consistent with the actual functionality of the script.
14-15
: Helpful addition of alternative command.Adding the alternative command (
pnpm lint
) is useful for users who might be more familiar with the lint command for checking issues.
18-26
: Excellent detailed explanation of check-redirects functionality.This comprehensive explanation of what the check-redirects script does and doesn't do is very valuable. It clearly outlines the script's purpose and limitations, helping users understand exactly what to expect.
35-35
: Updated example output for consistency.The example output has been updated to use "Pages with outdated links" instead of referring to broken links, maintaining terminology consistency.
39-39
: Better terminology in section title.Changing "Fixing broken links" to "Fixing outdated links" in the section title is more accurate and consistent with the actual functionality of the script.
44-45
: Helpful addition of alternative command.Adding the alternative command (
pnpm fix
) is useful for users who might prefer a shorter command to fix issues.
48-58
: Excellent detailed explanation of fix-redirects functionality.This comprehensive explanation of what the fix-redirects script does is very valuable. It clearly outlines the script's capabilities, including handling both Markdown and HTML links, saving modified files, and reporting changes.
63-68
: Updated example output for clarity and consistency.The example output has been updated to use "Pages fixed" and "Pages unchanged" terminology, which better reflects what the script does and maintains consistency with the script's actual output.
utils/fix-redirects.ts (12)
1-2
: Improved script identification and clarity!Adding a shebang line and descriptive comment enhances script identification and usability, allowing direct execution and clarifying the file's purpose.
9-9
: Better variable naming for clarity.Renaming the variable from
updates
tofixed
is a good change that better reflects the purpose of the array - to track fixed links rather than generic updates.
26-26
: Improved terminology in Summary interface.Changing
skipped
tounchanged
in the Summary interface is more descriptive and accurately represents files that didn't need modifications, rather than suggesting they were intentionally skipped.
29-42
: Enhanced error handling in getRedirects function.Adding try-catch error handling for file operations is an excellent improvement. This prevents the script from crashing when the redirects file can't be read and provides a meaningful error message.
47-60
: Enhanced error handling in findMdxFiles function.The addition of try-catch error handling for directory operations is a valuable improvement. This ensures the script continues execution even if a directory can't be accessed, logging the error instead of crashing.
65-100
: Significantly improved fixFile function with better error handling and safety checks.The enhancements to the fixFile function include:
- Proper error handling for file operations
- Addition of a
fileChanged
flag to accurately track modifications- Proper escaping of special characters in regex patterns to prevent potential regex errors
- Clear tracking of which files were modified before writing changes
These changes make the function more robust and reliable.
105-108
: Improved summary output terminology.Changing "files" to "pages" and "skipped" to "unchanged" in the summary output provides more accurate and consistent terminology throughout the application.
114-114
: Improved field naming for consistency.Changing the field name from
skipped
tounchanged
ensures consistency with the interface definition.
121-135
: Added essential directory and file existence checks.Adding explicit checks for the existence of the root directory and redirects file before proceeding is an excellent improvement. This prevents cryptic errors later in the process and provides clear error messages about missing prerequisites.
138-142
: Added informative logging.The added log messages about the number of redirects loaded and MDX files found provide better visibility into the script's operations, which is helpful for both users and debugging.
154-159
: Improved output message clarity.Changing "fixed broken links" to "fixed outdated links" in the output message is more accurate and consistent with the terminology used throughout the application.
168-168
: Added clarifying comment.Adding a comment for script execution enhances code readability and maintainability.
Description
This PR enhances our redirect link management tools and adds comprehensive documentation to clarify their purpose and functionality.
Changes:
redirects.ts
andfix-redirects.ts
Tests
Additional context
Metadata