Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/frame/components/context/MainContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export type MainContextT = {
hidden: boolean
noEarlyAccessBanner: boolean
applicableVersions: string[]
docsTeamMetrics?: string[]
docsTeamMetrics: string[] | null
} | null
relativePath?: string
sidebarTree?: ProductTreeNode | null
Expand Down Expand Up @@ -228,7 +228,7 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
applicableVersions: req.context.page?.permalinks.map((obj: any) => obj.pageVersion) || [],
hidden: req.context.page.hidden || false,
noEarlyAccessBanner: req.context.page.noEarlyAccessBanner || false,
docsTeamMetrics: req.context.page.docsTeamMetrics || undefined,
docsTeamMetrics: req.context.page.docsTeamMetrics || null,
}) ||
null

Expand Down
6 changes: 5 additions & 1 deletion src/links/lib/extract-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,17 @@ export function getRelativePath(filePath: string): string {
/**
* Normalize a link path for comparison with pageMap
*
* - Removes query strings
* - Removes trailing slashes
* - Removes anchor fragments
* - Ensures leading slash
*/
export function normalizeLinkPath(href: string): string {
// Remove query string
let normalized = href.split('?')[0]

// Remove anchor
let normalized = href.split('#')[0]
normalized = normalized.split('#')[0]

// Remove trailing slash
if (normalized.endsWith('/') && normalized.length > 1) {
Expand Down
16 changes: 16 additions & 0 deletions src/links/tests/extract-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,22 @@ describe('normalizeLinkPath', () => {
'/en/enterprise-server@3.10/admin/overview',
)
})

test('removes query string', () => {
expect(normalizeLinkPath('/actions/guides?tab=cli')).toBe('/actions/guides')
})

test('removes query string before anchor fragment', () => {
expect(normalizeLinkPath('/actions/guides?tab=cli#section')).toBe('/actions/guides')
})

test('removes query string with trailing slash', () => {
expect(normalizeLinkPath('/actions/guides/?tab=cli')).toBe('/actions/guides')
})

test('handles path with only a query string (no anchor)', () => {
expect(normalizeLinkPath('/repositories/overview?version=3')).toBe('/repositories/overview')
})
})

describe('checkInternalLink', () => {
Expand Down
Loading