Files
supabase/apps/studio/lib/telemetry/docs-path.ts

18 lines
657 B
TypeScript

import { DOCS_URL } from '@/lib/constants'
export const getDocsPath = (href: string) => {
if (!href.startsWith(DOCS_URL)) return undefined
const afterDocsRoot = href.slice(DOCS_URL.length)
const isSiblingPath = !/^([/?#]|$)/.test(afterDocsRoot)
if (isSiblingPath) return undefined
const [, path = '', query = '', anchor = ''] =
/^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(afterDocsRoot) ?? []
// The advisor docs serve every lint from one path, so only the lint param says which doc opened
const lintId = new URLSearchParams(query).get('lint')
const lintQuery = lintId ? `?lint=${lintId}` : ''
return `${path}${lintQuery}${anchor}` || '/'
}