diff --git a/.github/workflows/sync-orama.yml b/.github/workflows/sync-orama.yml index 0402cac23d..b5575f8ec1 100644 --- a/.github/workflows/sync-orama.yml +++ b/.github/workflows/sync-orama.yml @@ -20,7 +20,7 @@ jobs: sync-orama-cloud: name: Sync Orama Cloud runs-on: ubuntu-latest - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + if: (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && github.actor != 'dependabot[bot]' steps: - name: 'Checkout' diff --git a/scripts/orama-documents.mjs b/scripts/orama-documents.mjs index 0b9a9668b1..414599f021 100644 --- a/scripts/orama-documents.mjs +++ b/scripts/orama-documents.mjs @@ -12,6 +12,12 @@ const stripMdxImports = (content) => content.replace(/^import\s+.*$/gm, ''); const mdToText = (content) => toString(fromMarkdown(stripMdxImports(content))).replace(/<[^>]*>/g, ''); +// Build the public path segment from a content-relative file path: drop the +// extension and any trailing `index` so `foo/index.mdx` -> `foo`. This matches +// Astro's glob loader, which serves index files at their directory URL (without +// a trailing `/index`). +const toPathSegment = (relPath) => relPath.replace(/\.mdx?$/, '').replace(/(?:^|\/)index$/, ''); + const collectMdFiles = async (dir, base = dir) => { const entries = await readdir(dir); const results = await Promise.all( @@ -35,14 +41,14 @@ export const getPages = async (lang) => { const fullPath = join(baseDir, file); const raw = await readFile(fullPath, 'utf-8'); const { data, content } = matter(raw); - const pathSegment = relative(baseDir, fullPath).replace(/\.mdx?$/, ''); + const pathSegment = toPathSegment(relative(baseDir, fullPath)); const isResource = pathSegment.startsWith('resources'); return { title: data.title ?? basename(file).replace(/\.mdx?$/, ''), description: data.description ?? '', content: mdToText(content), - path: `/${lang}/${pathSegment}`, + path: `/${lang}/${pathSegment}`.replace(/\/+$/, ''), category: isResource ? 'menu.main.resources' : 'menu.main.docs', }; }) @@ -58,13 +64,13 @@ export const getDocs = async (lang) => { const fullPath = join(baseDir, file); const raw = await readFile(fullPath, 'utf-8'); const { data, content } = matter(raw); - const pathSegment = relative(baseDir, fullPath).replace(/\.mdx?$/, ''); + const pathSegment = toPathSegment(relative(baseDir, fullPath)); return { title: data.title ?? basename(file).replace(/\.mdx?$/, ''), description: data.description ?? '', content: mdToText(content), - path: `/${lang}/${pathSegment}`, + path: `/${lang}/${pathSegment}`.replace(/\/+$/, ''), category: 'menu.main.docs', }; }) @@ -106,13 +112,13 @@ export const getApi = async (lang) => { const fullPath = join(baseDir, file); const raw = await readFile(fullPath, 'utf-8'); const { data, content } = matter(raw); - const pathSegment = relative(baseDir, fullPath).replace(/\.mdx?$/, ''); + const pathSegment = toPathSegment(relative(baseDir, fullPath)); return { title: data.title ?? basename(file).replace(/\.mdx?$/, ''), description: data.description ?? '', content: mdToText(content), - path: `/${lang}/${version}/${pathSegment}`, + path: `/${lang}/${version}/${pathSegment}`.replace(/\/+$/, ''), category: 'menu.main.api', version, };