Skip to content

Commit ab4ca9f

Browse files
committed
feat: enable validate-links & support 2 hash formats
Update link normalization logic to remove any trailing slash after stripping query parameters and hash fragments. This ensures that both "api/interfaces/MetadataFilter#operator" and "api/interfaces/MetadataFilter/#operator" are correctly normalized.
1 parent dccd444 commit ab4ca9f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

apps/next/scripts/validate-links.mts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,12 @@ async function validateLinks(): Promise<LinkValidationResult[]> {
162162
const invalidLinks = links.filter(({ link }) => {
163163
// Check if the link exists in valid routes
164164
// First normalize the link (remove any query string or hash)
165-
const normalizedLink = link.split("#")[0].split("?")[0];
165+
const baseLink = link.split("?")[0].split("#")[0];
166+
// Remove the trailing slash if present.
167+
// This works with links like "api/interfaces/MetadataFilter#operator" and "api/interfaces/MetadataFilter/#operator".
168+
const normalizedLink = baseLink.endsWith("/")
169+
? baseLink.slice(0, -1)
170+
: baseLink;
166171

167172
// Remove llamaindex/ prefix if it exists as it's the root of the docs
168173
let routePath = normalizedLink;
@@ -192,8 +197,7 @@ async function main() {
192197

193198
try {
194199
// Check for invalid internal links
195-
const validationResults: LinkValidationResult[] = [];
196-
await validateLinks();
200+
const validationResults: LinkValidationResult[] = await validateLinks();
197201
// Check for relative links
198202
const relativeLinksResults = await findRelativeLinks();
199203

0 commit comments

Comments
 (0)