Skip to content

Fix edit link generation and reduce 404 errors#5318

Open
ksaini-web wants to merge 1 commit into
asyncapi:masterfrom
ksaini-web:fix/edit-links-404
Open

Fix edit link generation and reduce 404 errors#5318
ksaini-web wants to merge 1 commit into
asyncapi:masterfrom
ksaini-web:fix/edit-links-404

Conversation

@ksaini-web
Copy link
Copy Markdown

@ksaini-web ksaini-web commented Apr 5, 2026

Description

This PR improves how edit links are generated in check-edit-links.ts.

Earlier, the script was using only the file name to build edit links. Because of this, many links were incorrect and resulted in 404 errors.

What I changed

  • Used the full relative path instead of just the file name
  • Normalized file paths so it works correctly on Windows and other systems
  • Added handling for different repository structures (like bindings and spec)
  • Kept fallback logic for safety

Result

After these changes, many incorrect edit links are fixed and 404 errors are reduced.

Note

Some links are still showing as invalid because of differences in external repository structures (for example, bindings repo uses folder-based README files). These are not caused by this script.

Resolves #5151

Summary by CodeRabbit

  • Chores
    • Updated edit link configuration and path handling to improve consistency across different operating systems and refine link generation for documentation resources.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 5, 2026

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e2f138c
🔍 Latest deploy log https://app.netlify.com/projects/asyncapi-website/deploys/69d2670acf3d4e00084866bf
😎 Deploy Preview https://deploy-preview-5318--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@asyncapi-bot
Copy link
Copy Markdown
Contributor

asyncapi-bot commented Apr 5, 2026

We require all PRs to follow Conventional Commits specification.
More details 👇🏼

 No release type found in pull request title "Fix edit link generation and reduce 404 errors". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 5, 2026

📝 Walkthrough

Walkthrough

The changes address broken edit link generation by adjusting configuration URLs and refactoring the edit link logic to use full relative paths with cross-platform path normalization and prefix removal for specification references.

Changes

Cohort / File(s) Summary
Configuration Updates
config/edit-page-config.json
Updated bindings href from /tree/master to /blob/master URL pattern and changed specification href from specific .../asyncapi.md path to broader .../spec directory reference.
Edit Link Generation Logic
scripts/markdown/check-edit-links.ts
Refactored processBatch to normalize file paths using forward slashes before ignore-file matching. Enhanced determineEditLink to generate links using full relative paths instead of basename, with fallback logic and removal of reference/bindings/ and reference/specification/ prefixes when applicable. Added explicit null return for unmatched configs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A config tweak and path so clean,
Forward slashes, cross-platform seen,
Edit links now find their way,
No more 404s to slay!
GitHub URLs shine so bright,

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially implements the proposed objectives from #5151. It normalizes file paths for cross-platform consistency and uses full relative paths instead of just filenames, fixing some 404 errors. However, it does not fully implement the core requirement: dynamically detecting available spec versions from the filesystem using semantic version pattern matching. Implement dynamic version detection by reading the specification directory with fs module and matching entries against semantic version patterns (v\d+\.\d+\.\d+). Pass discovered versions to determineEditLink to auto-generate edit links without manual allowlist maintenance.
Out of Scope Changes check ❓ Inconclusive The PR includes a configuration file change (config/edit-page-config.json) updating href values for bindings and specification entries, which appears related to supporting the different repository structures mentioned in PR objectives but is not explicitly discussed in linked issue #5151. Clarify whether the config/edit-page-config.json changes are necessary for fixing the 404 errors or if they represent an out-of-scope configuration update. Link these changes to the PR objectives for transparency.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly summarizes the main change: fixing edit link generation logic and reducing 404 errors. It is concise, specific, and directly relates to the code changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 5, 2026

@asyncapi-bot
Copy link
Copy Markdown
Contributor

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 46
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-5318--asyncapi-website.netlify.app/

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.

🧹 Nitpick comments (3)
config/edit-page-config.json (1)

2-5: Minor JSON formatting inconsistency.

The first entry (lines 2-5) lacks the 2-space indentation that all other entries in the array have. This doesn't affect functionality but creates inconsistent formatting.

🔧 Suggested fix for consistent indentation
 [
-{
-  "value": "reference/bindings/",
-  "href": "https://github.com/asyncapi/bindings/blob/master"
-},
+  {
+    "value": "reference/bindings/",
+    "href": "https://github.com/asyncapi/bindings/blob/master"
+  },
   {
     "value": "/tools/generator",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@config/edit-page-config.json` around lines 2 - 5, The JSON entry with
"value": "reference/bindings/" and "href":
"https://github.com/asyncapi/bindings/blob/master" has inconsistent indentation
compared to the other array entries; reformat that object to use the same
2-space indentation as the rest of entries in edit-page-config.json so it aligns
visually with surrounding items (locate the object by the "value":
"reference/bindings/" key to make the change).
scripts/markdown/check-edit-links.ts (2)

154-172: Inconsistent indentation within the function.

The code blocks from lines 154-172 have inconsistent indentation compared to lines 143-152. This affects readability and maintainability.

🔧 Suggested fix for consistent indentation
-// Safety fallback: if extraction fails, use filename only
-if (!relativePath) {
-  return `${target.href}/${path.basename(filePath)}`;
-}
-
-// Some external repos do not keep the same docs-side folder structure,
-// so remove those prefixes before building the final edit link.
-let repoRelativePath = relativePath;
-
-if (target.href.includes('asyncapi/bindings')) {
-  repoRelativePath = repoRelativePath.replace('reference/bindings/', '');
-}
-
-if (target.href.includes('asyncapi/spec')) {
-  repoRelativePath = repoRelativePath.replace('reference/specification/', '');
-}
-
-// Construct correct GitHub edit link
-return `${target.href}/${repoRelativePath}`;
+    // Safety fallback: if extraction fails, use filename only
+    if (!relativePath) {
+      return `${target.href}/${path.basename(filePath)}`;
+    }
+
+    // Some external repos do not keep the same docs-side folder structure,
+    // so remove those prefixes before building the final edit link.
+    let repoRelativePath = relativePath;
+
+    if (target.href.includes('asyncapi/bindings')) {
+      repoRelativePath = repoRelativePath.replace('reference/bindings/', '');
+    }
+
+    if (target.href.includes('asyncapi/spec')) {
+      repoRelativePath = repoRelativePath.replace('reference/specification/', '');
+    }
+
+    // Construct correct GitHub edit link
+    return `${target.href}/${repoRelativePath}`;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/markdown/check-edit-links.ts` around lines 154 - 172, The block
handling the safety fallback and repo-specific path fixes in check-edit-links.ts
(references: variables relativePath, repoRelativePath, target.href, filePath and
the final return) has inconsistent indentation compared to the earlier logic;
reformat that entire section so its indentation style matches the surrounding
lines (align the if/return blocks and inner repoRelativePath.replace calls with
the earlier code style), preserving the same statements and behavior but making
bracketed blocks and return lines consistently indented for readability.

174-181: Minor code style inconsistencies.

There are a few formatting issues:

  • Extra blank lines inside the if block (lines 174-175)
  • Missing semicolon on return null (line 178)
  • Extra blank lines after the function closing brace
🔧 Suggested cleanup
 // Construct correct GitHub edit link
 return `${target.href}/${repoRelativePath}`;
-
-  
-  
 }
-  // If no matching config found, return null
-return null
-}
-
-
+  // If no matching config found, return null
+  return null;
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/markdown/check-edit-links.ts` around lines 174 - 181, Fix the minor
formatting issues in the function at the end of
scripts/markdown/check-edit-links.ts that returns a matching config or null:
remove the extra blank lines inside the if block, add a missing semicolon to the
`return null` statement, and delete the stray blank lines after the function's
closing brace so the function ends cleanly. Locate the function that performs
the matching and ends with `return null` and apply these style corrections.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@config/edit-page-config.json`:
- Around line 2-5: The JSON entry with "value": "reference/bindings/" and
"href": "https://github.com/asyncapi/bindings/blob/master" has inconsistent
indentation compared to the other array entries; reformat that object to use the
same 2-space indentation as the rest of entries in edit-page-config.json so it
aligns visually with surrounding items (locate the object by the "value":
"reference/bindings/" key to make the change).

In `@scripts/markdown/check-edit-links.ts`:
- Around line 154-172: The block handling the safety fallback and repo-specific
path fixes in check-edit-links.ts (references: variables relativePath,
repoRelativePath, target.href, filePath and the final return) has inconsistent
indentation compared to the earlier logic; reformat that entire section so its
indentation style matches the surrounding lines (align the if/return blocks and
inner repoRelativePath.replace calls with the earlier code style), preserving
the same statements and behavior but making bracketed blocks and return lines
consistently indented for readability.
- Around line 174-181: Fix the minor formatting issues in the function at the
end of scripts/markdown/check-edit-links.ts that returns a matching config or
null: remove the extra blank lines inside the if block, add a missing semicolon
to the `return null` statement, and delete the stray blank lines after the
function's closing brace so the function ends cleanly. Locate the function that
performs the matching and ends with `return null` and apply these style
corrections.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f36517ac-4fae-4a3d-8013-36625c931c69

📥 Commits

Reviewing files that changed from the base of the PR and between 278f84d and e2f138c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • config/edit-page-config.json
  • scripts/markdown/check-edit-links.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Be Triaged

Development

Successfully merging this pull request may close these issues.

[BUG] check-edit-links generates 404s

2 participants