Files
supabase/apps/docs/scripts/search/sources/index.ts
Illia Basalaiev ce5cce5030 replace github discussions with local guides in the docs search (#42335)
## I have read the
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
file.

YES

## What kind of change does this PR introduce?

feature

## What is the current behavior?

Currently, old GitHub discussions appear in the docs search instead of
troubleshooting guides in docs/guides/troubleshooting

## What is the new behavior?

Local troubleshooting guides appear in the search

## Additional context

<img width="958" height="846" alt="CleanShot 2026-01-31 at 23 37 33@2x"
src="https://github.com/user-attachments/assets/445fab5d-764a-4b4d-b4ef-c29ab675a9ae"
/>


**troubleshooting.ts** - New source loader that reads local MDX files
from content/troubleshooting/ directly instead of fetching from GitHub
Discussions API
- Generates correct docs paths: /guides/troubleshooting/{slug}
- Uses type = 'troubleshooting' for proper search result mapping
- Sets slug: undefined to avoid trailing # in URLs
- Checksum includes title/topics/keywords so metadata-only changes
trigger re-indexing
- Left comments for review 

**index.ts** - Replaced GitHub discussion sources with local
troubleshooting sources
- Removed GitHubDiscussionLoader, fetchDiscussions,
buildGithubUrlToSlugMap imports
- Added fetchTroubleshootingSources and TroubleshootingSource
- Updated SearchSource type union

**globalSearchModel.ts** - Changed type mapping from
'github-discussions' to 'troubleshooting'

**generate-embeddings.ts** - Removed GitHub App env vars from required
list (DOCS_GITHUB_APP_ID, DOCS_GITHUB_APP_INSTALLATION_ID,
DOCS_GITHUB_APP_PRIVATE_KEY) since they're no longer needed


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Local troubleshooting articles are now indexed and appear directly in
search results for easier access to step‑by‑step guidance.
* Search UI now recognizes a Troubleshooting page type and shows
appropriate icons/sections.

* **Refactor**
* Search sourcing switched from external discussion feeds to local
troubleshooting sources to improve relevance and indexing consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Illia Basalaiev <illiab@IMB3.local>
Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
Co-authored-by: Chris Chinchilla <chris.ward@supabase.io>
2026-02-23 13:54:40 +01:00

176 lines
5.5 KiB
TypeScript

import { type GuideModel } from '../../../resources/guide/guideModel.js'
import { GuideModelLoader } from '../../../resources/guide/guideModelLoader.js'
import { LintWarningsGuideLoader, type LintWarningsGuideSource } from './lint-warnings-guide.js'
import { MarkdownLoader, type MarkdownSource } from './markdown.js'
import { IntegrationLoader, type IntegrationSource, fetchPartners } from './partner-integrations.js'
import {
CliReferenceLoader,
type CliReferenceSource,
ClientLibReferenceLoader,
type ClientLibReferenceSource,
OpenApiReferenceLoader,
type OpenApiReferenceSource,
} from './reference-doc.js'
import { fetchTroubleshootingSources, type TroubleshootingSource } from './troubleshooting.js'
export type SearchSource =
| MarkdownSource
| OpenApiReferenceSource
| ClientLibReferenceSource
| CliReferenceSource
| TroubleshootingSource
| IntegrationSource
| LintWarningsGuideSource
export async function fetchGuideSources() {
const guides = (await GuideModelLoader.allFromFs()).unwrapLeft()
return guides.map((guide: GuideModel) => MarkdownLoader.fromGuideModel('guide', guide))
}
export async function fetchOpenApiReferenceSource() {
return new OpenApiReferenceLoader(
'api',
'/reference/api',
{ title: 'Management API Reference' },
'spec/transforms/api_v1_openapi_deparsed.json',
'spec/common-api-sections.json'
).load()
}
export async function fetchJsLibReferenceSource() {
return new ClientLibReferenceLoader(
'js-lib',
'/reference/javascript',
{ title: 'JavaScript Reference', language: 'JavaScript' },
'spec/supabase_js_v2.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchDartLibReferenceSource() {
return new ClientLibReferenceLoader(
'dart-lib',
'/reference/dart',
{ title: 'Dart Reference', language: 'Dart' },
'spec/supabase_dart_v2.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchPythonLibReferenceSource() {
return new ClientLibReferenceLoader(
'python-lib',
'/reference/python',
{ title: 'Python Reference', language: 'Python' },
'spec/supabase_py_v2.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchCSharpLibReferenceSource() {
return new ClientLibReferenceLoader(
'csharp-lib',
'/reference/csharp',
{ title: 'C# Reference', language: 'C#' },
'spec/supabase_csharp_v0.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchSwiftLibReferenceSource() {
return new ClientLibReferenceLoader(
'swift-lib',
'/reference/swift',
{ title: 'Swift Reference', language: 'Swift' },
'spec/supabase_swift_v2.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchKtLibReferenceSource() {
return new ClientLibReferenceLoader(
'kt-lib',
'/reference/kotlin',
{ title: 'Kotlin Reference', language: 'Kotlin' },
'spec/supabase_kt_v1.yml',
'spec/common-client-libs-sections.json'
).load()
}
export async function fetchCliLibReferenceSource() {
return new CliReferenceLoader(
'cli',
'/reference/cli',
{ title: 'CLI Reference', platform: 'cli' },
'spec/cli_v1_commands.yaml',
'spec/common-cli-sections.json'
).load()
}
export async function fetchLintWarningsGuideSources() {
return new LintWarningsGuideLoader(
'guide',
'/guides/database/database-advisors',
'supabase',
'splinter',
'main',
'docs'
).load()
}
/**
* Fetches all the sources we want to index for search
*/
export async function fetchAllSources(fullIndex: boolean) {
const guideSources = fetchGuideSources()
const lintWarningsGuideSources = fetchLintWarningsGuideSources()
const openApiReferenceSource = fetchOpenApiReferenceSource()
const jsLibReferenceSource = fetchJsLibReferenceSource()
const dartLibReferenceSource = fullIndex ? fetchDartLibReferenceSource() : []
const pythonLibReferenceSource = fullIndex ? fetchPythonLibReferenceSource() : []
const cSharpLibReferenceSource = fullIndex ? fetchCSharpLibReferenceSource() : []
const swiftLibReferenceSource = fullIndex ? fetchSwiftLibReferenceSource() : []
const ktLibReferenceSource = fullIndex ? fetchKtLibReferenceSource() : []
const cliReferenceSource = fullIndex ? fetchCliLibReferenceSource() : []
const partnerIntegrationSources = fullIndex
? fetchPartners()
.then((partners) =>
partners
? Promise.all(
partners.map((partner) => new IntegrationLoader(partner.slug, partner).load())
)
: []
)
.then((data) => data.flat())
: []
// Load troubleshooting articles from local MDX files
const troubleshootingSources = fetchTroubleshootingSources()
.then((loaders) => Promise.all(loaders.map((loader) => loader.load())))
.then((data) => data.flat())
// Type assertion required because ReferenceLoader.load() returns Promise<BaseSource[]>
// which widens the inferred union type. All concrete sources in this array are valid
// SearchSource types (MarkdownSource, OpenApiReferenceSource, etc.).
const sources = (
await Promise.all([
guideSources,
lintWarningsGuideSources,
openApiReferenceSource,
jsLibReferenceSource,
dartLibReferenceSource,
pythonLibReferenceSource,
cSharpLibReferenceSource,
swiftLibReferenceSource,
ktLibReferenceSource,
cliReferenceSource,
partnerIntegrationSources,
troubleshootingSources,
])
).flat() as SearchSource[]
return sources
}