mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
Merge pull request #14297 from supabase/fix/search-custom-slugs
fix(embeddings): custom heading slugs
This commit is contained in:
2 files changed
+41
-5
No files matched your search
@@ -9,7 +9,12 @@ on:
|
||||
- 'supabase/migrations/**'
|
||||
- 'apps/docs/**'
|
||||
- 'spec/**'
|
||||
workflow_dispatch: {}
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
refresh:
|
||||
description: 'Refresh all pages'
|
||||
required: false
|
||||
type: boolean
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
|
||||
@@ -46,6 +51,12 @@ jobs:
|
||||
- name: Run migrations
|
||||
run: npx supabase db push
|
||||
|
||||
- name: Update embeddings
|
||||
working-directory: ./apps/docs
|
||||
if: ${{ !inputs.refresh }}
|
||||
run: npm run embeddings
|
||||
|
||||
- name: Refresh embeddings
|
||||
working-directory: ./apps/docs
|
||||
run: npm run embeddings
|
||||
if: ${{ inputs.refresh }}
|
||||
run: npm run embeddings:refresh
|
||||
@@ -96,6 +96,23 @@ export function splitTreeBy(tree: Root, predicate: (node: Content) => boolean) {
|
||||
}, [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a markdown heading which can optionally
|
||||
* contain a custom anchor in the format:
|
||||
*
|
||||
* ```markdown
|
||||
* ### My Heading [#my-custom-anchor]
|
||||
* ```
|
||||
*/
|
||||
export function parseHeading(heading: string): { heading: string; customAnchor?: string } {
|
||||
const match = heading.match(/(.*) *\[#(.*)\]/)
|
||||
if (match) {
|
||||
const [, heading, customAnchor] = match
|
||||
return { heading, customAnchor }
|
||||
}
|
||||
return { heading }
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes MDX content for search indexing.
|
||||
* It extracts metadata, strips it of all JSX,
|
||||
@@ -140,12 +157,20 @@ export function processMdxForSearch(content: string): ProcessedMdx {
|
||||
|
||||
const sections = sectionTrees.map((tree) => {
|
||||
const [firstNode] = tree.children
|
||||
const content = toMarkdown(tree)
|
||||
|
||||
const heading = firstNode.type === 'heading' ? toString(firstNode) : undefined
|
||||
const slug = heading ? slugger.slug(heading) : undefined
|
||||
const rawHeading: string = firstNode.type === 'heading' ? toString(firstNode) : undefined
|
||||
|
||||
if (!rawHeading) {
|
||||
return { content }
|
||||
}
|
||||
|
||||
const { heading, customAnchor } = parseHeading(rawHeading)
|
||||
|
||||
const slug = slugger.slug(customAnchor ?? heading)
|
||||
|
||||
return {
|
||||
content: toMarkdown(tree),
|
||||
content,
|
||||
heading,
|
||||
slug,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user