mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 01:15:03 +03:00
Add crawler slugs for all libs
This commit is contained in:
1 parent
956d42896c
commit
1e242b16cf
4 files changed
+114
-2
No files matched your search
+12
-2
@@ -2,17 +2,27 @@ import { NextResponse } from 'next/server'
|
||||
import type { NextRequest } from 'next/server'
|
||||
import isbot from 'isbot'
|
||||
|
||||
// This function can be marked `async` if using `await` inside
|
||||
export function middleware(request: NextRequest) {
|
||||
const specs = ['javascript', 'dart']
|
||||
|
||||
let version = ''
|
||||
if (request.url.includes('/v1/')) {
|
||||
version = 'v1'
|
||||
}
|
||||
if (request.url.includes('/v0/')) {
|
||||
version = 'v0'
|
||||
}
|
||||
|
||||
if (isbot(request.headers.get('user-agent'))) {
|
||||
for (const lib of specs) {
|
||||
if (request.url.includes(`reference/${lib}`)) {
|
||||
const requestSlug = request.url.split('/').pop()
|
||||
|
||||
return NextResponse.rewrite(
|
||||
new URL(`/docs/reference/${lib}/crawlers/${requestSlug}`, request.url).toString()
|
||||
new URL(
|
||||
`/docs/reference/${lib}/${version ? version + '/' : ''}crawlers/${requestSlug}`,
|
||||
request.url
|
||||
).toString()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json'
|
||||
import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json'
|
||||
// @ts-expect-error
|
||||
import spec from '~/../../spec/supabase_dart_v1.yml' assert { type: 'yml' }
|
||||
import RefSectionHandler from '~/components/reference/RefSectionHandler'
|
||||
import { flattenSections } from '~/lib/helpers'
|
||||
import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths'
|
||||
import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
const sections = flattenSections(clientLibsCommonSections)
|
||||
|
||||
export default function JSReference(props) {
|
||||
const router = useRouter()
|
||||
const slug = router.query.slug[0]
|
||||
const filteredSection = sections.filter((section) => section.id === slug)
|
||||
|
||||
return (
|
||||
<RefSectionHandler
|
||||
sections={filteredSection}
|
||||
spec={spec}
|
||||
typeSpec={typeSpec}
|
||||
pageProps={props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params }: { params: { slug: string[] } }) {
|
||||
return handleRefStaticProps(sections, params, '/dart', '/dart')
|
||||
}
|
||||
|
||||
export function getStaticPaths() {
|
||||
return handleRefGetStaticPaths()
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json'
|
||||
import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json'
|
||||
// @ts-expect-error
|
||||
import spec from '~/../../spec/supabase_dart_v0.yml' assert { type: 'yml' }
|
||||
import RefSectionHandler from '~/components/reference/RefSectionHandler'
|
||||
import { flattenSections } from '~/lib/helpers'
|
||||
import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths'
|
||||
import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
const sections = flattenSections(clientLibsCommonSections)
|
||||
|
||||
export default function JSReference(props) {
|
||||
const router = useRouter()
|
||||
const slug = router.query.slug[0]
|
||||
const filteredSection = sections.filter((section) => section.id === slug)
|
||||
|
||||
return (
|
||||
<RefSectionHandler
|
||||
sections={filteredSection}
|
||||
spec={spec}
|
||||
typeSpec={typeSpec}
|
||||
pageProps={props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params }: { params: { slug: string[] } }) {
|
||||
return handleRefStaticProps(sections, params, '/dart/v0', '/dart/v0')
|
||||
}
|
||||
|
||||
export function getStaticPaths() {
|
||||
return handleRefGetStaticPaths()
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json'
|
||||
import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json'
|
||||
// @ts-expect-error
|
||||
import spec from '~/../../spec/supabase_js_v1.yml' assert { type: 'yml' }
|
||||
import RefSectionHandler from '~/components/reference/RefSectionHandler'
|
||||
import { flattenSections } from '~/lib/helpers'
|
||||
import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths'
|
||||
import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
const sections = flattenSections(clientLibsCommonSections)
|
||||
|
||||
export default function JSReference(props) {
|
||||
const router = useRouter()
|
||||
const slug = router.query.slug[0]
|
||||
const filteredSection = sections.filter((section) => section.id === slug)
|
||||
|
||||
return (
|
||||
<RefSectionHandler
|
||||
sections={filteredSection}
|
||||
spec={spec}
|
||||
typeSpec={typeSpec}
|
||||
pageProps={props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params }: { params: { slug: string[] } }) {
|
||||
return handleRefStaticProps(sections, params, '/javascript/v1', '/javascript/v1')
|
||||
}
|
||||
|
||||
export function getStaticPaths() {
|
||||
return handleRefGetStaticPaths()
|
||||
}
|
||||
Reference in new issue
Block a user