mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
18 lines
657 B
TypeScript
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}` || '/'
|
|
}
|