Skip to content

Incremental engine for long horizon agents 🌟 Star if you like it!

fix(docs): close the gaps the Python/Rust content pass found in the language machinery (#2756)

LJ πŸ₯₯🌴ccb8a90f479c
diff --git a/docs/CONTENT_LANGUAGES.md b/docs/CONTENT_LANGUAGES.md
index e5cbb56c..9010f1f0 100644
--- a/docs/CONTENT_LANGUAGES.md
+++ b/docs/CONTENT_LANGUAGES.md
@@ -81,6 +81,15 @@ code. A heading inside appears only in that language's table of contents:
Do not nest `Lang` in `Lang`.
+### `<LangCardGrid>`: a section overview's card grid
+
+The brand `DocCardGrid` with each card's link pointed into the reader's tree.
+Keep `src/data/section-grids.ts` written in Python-tree URLs:
+
+```mdx
+<LangCardGrid groups={advancedTopicsGroups} ariaLabel="Advanced topics" />
+```
+
### `<RustNote>`: a difference from Python
Shown on Rust pages only, as a callout titled "Different from Python". Use it
@@ -98,8 +107,10 @@ The Rust SDK has no sync/async adapter: a `#[cocoindex::function]` body is an
## Links
- A **source-relative** link (`./app`, `../connectors/postgres`) opens the
- linked file's page in the reader's language when the page has one, else in
- the language it has. Write these by default.
+ linked file's page in the reader's language when the page has one, else the
+ counterpart the page declares for that language (`../ops/litellm` opens
+ Model APIs on a Rust page), else the page in the language it has. Write
+ these by default.
- A **root-relative** link (`/docs/cli/`, `/docs/rust/cli/`) is taken as
written. Use it to point at one language on purpose, for example "see the
[Python CLI](/docs/cli/)" on a Rust page.
@@ -109,7 +120,8 @@ The Rust SDK has no sync/async adapter: a `#[cocoindex::function]` body is an
Each language has its own `.md` twins (`/docs/<slug>.md`,
`/docs/rust/<slug>.md`), `llms.txt` and `llms-full.txt`. The twins keep only
the page's language: `Lang`, `LangTabs` slots and `RustNote` of the other
-language are dropped. `scripts/check-agent-output.mjs` checks that every page
+language are dropped, source-relative links resolve as in the HTML page, and
+a Rust twin opens with a Rust SDK banner. `scripts/check-agent-output.mjs` checks that every page
has a twin per language and that every code block appears in one of them.
## Reference page
diff --git a/docs/scripts/check-agent-output.mjs b/docs/scripts/check-agent-output.mjs
index 2b2a5930..d4927081 100644
--- a/docs/scripts/check-agent-output.mjs
+++ b/docs/scripts/check-agent-output.mjs
@@ -173,25 +173,40 @@ for (const dir of readdirSync(EXAMPLES_DIR)) {
// Catches the drift class where a page ships in the sidebar but the
// hand-curated overview (tables / card grids) silently omits it β€” a
// Snowflake-sized hole in a page that claims to be exhaustive.
+// Per SDK language: each tree's overview must link that tree's pages
+// (a sidebar slot exists in a tree when a page there takes its route).
{
const sidebarSrc = read(here('../src/data/docs-sidebar.ts'));
const slugs = [...sidebarSrc.matchAll(/\{ type: 'doc', slug: '([^']+)'/g)].map((m) => m[1]);
- const sections = slugs.filter((s) => !s.includes('/'));
- for (const section of sections) {
- const pages = slugs.filter((s) => s.startsWith(`${section}/`));
- if (!pages.length) continue;
- const overviewPath = join(DIST, section, 'index.html');
- if (!existsSync(overviewPath)) {
- errors.push(`missing dist/${section}/index.html (section overview)`);
- continue;
+ const trees = { python: new Set(), rust: new Set() };
+ for (const src of contentFiles(DOCS_SRC)) {
+ for (const twin of docTwins(src)) {
+ const route = twin.replace(/\.md$/, '');
+ if (route.startsWith('rust/')) trees.rust.add(route.slice('rust/'.length));
+ else trees.python.add(route);
}
- const html = read(overviewPath);
- // scope to the article body so the sidebar's own nav links don't satisfy
- // the check; fall back to the full page if the marker is absent.
- const main = html.slice(html.indexOf('<main'), html.lastIndexOf('</main>') + 1) || html;
- for (const page of pages) {
- if (!main.includes(`/docs/${page}/`) && !main.includes(`/docs/${page}"`))
- errors.push(`section overview /docs/${section}/ does not link /docs/${page}/`);
+ }
+ const sections = slugs.filter((s) => !s.includes('/'));
+ for (const [lang, tree] of Object.entries(trees)) {
+ const prefix = lang === 'python' ? '' : `${lang}/`;
+ for (const section of sections) {
+ if (!tree.has(section)) continue;
+ const pages = slugs.filter((s) => s.startsWith(`${section}/`) && tree.has(s));
+ if (!pages.length) continue;
+ const overviewPath = join(DIST, prefix, section, 'index.html');
+ if (!existsSync(overviewPath)) {
+ errors.push(`missing dist/${prefix}${section}/index.html (section overview)`);
+ continue;
+ }
+ const html = read(overviewPath);
+ // scope to the article body so the sidebar's own nav links don't satisfy
+ // the check; fall back to the full page if the marker is absent.
+ const main = html.slice(html.indexOf('<main'), html.lastIndexOf('</main>') + 1) || html;
+ for (const page of pages) {
+ const url = `/docs/${prefix}${page}`;
+ if (!main.includes(`${url}/`) && !main.includes(`${url}"`))
+ errors.push(`section overview /docs/${prefix}${section}/ does not link ${url}/`);
+ }
}
}
}
diff --git a/docs/src/components/LangCardGrid.astro b/docs/src/components/LangCardGrid.astro
new file mode 100644
index 00000000..cbdfa677
--- /dev/null
+++ b/docs/src/components/LangCardGrid.astro
@@ -0,0 +1,24 @@
+---
+// The brand DocCardGrid with each card's link pointed into the reader's SDK
+// language tree: a card written as `/docs/<slug>/` opens `/docs/rust/<slug>/`
+// on a Rust page when that page exists there. Use it instead of DocCardGrid
+// in docs pages, with the same props; section-grids.ts stays written in
+// Python-tree URLs. Needs no import in a page.
+import DocCardGrid from '@cocoindex/brand/DocCardGrid.astro';
+import { DOCS_BASE } from '../consts';
+import { currentLang, langHref, pageRegistry } from '../lib/lang';
+
+type Props = Parameters<typeof DocCardGrid>[0];
+const { groups, ariaLabel } = Astro.props;
+const lang = currentLang(Astro);
+const reg = await pageRegistry();
+const localize = (href: string): string => {
+ if (!href.startsWith(`${DOCS_BASE}/`)) return href;
+ const [path, hash] = href.slice(DOCS_BASE.length + 1).split('#');
+ const route = path.replace(/\/$/, '');
+ if (!reg.at(lang, route)) return href;
+ return langHref(lang, route) + (hash ? `#${hash}` : '');
+};
+const localized = groups.map((g) => ({ ...g, cards: g.cards.map((c) => ({ ...c, href: localize(c.href) })) }));
+---
+<DocCardGrid groups={localized} ariaLabel={ariaLabel} />
diff --git a/docs/src/components/MobileSheet.astro b/docs/src/components/MobileSheet.astro
index f6e1c64d..3205c2ce 100644
--- a/docs/src/components/MobileSheet.astro
+++ b/docs/src/components/MobileSheet.astro
@@ -13,7 +13,7 @@ import { sidebar, type SidebarItem } from '../data/docs-sidebar';
import { SITE_MAIN, SITE_BLOG, SITE_EXAMPLES } from '../consts';
import Search from './Search.astro';
import LangSwitch from './LangSwitch.astro';
-import { langHref, type Lang } from '../lib/lang';
+import { DEFAULT_LANG, langHref, pageRegistry, sidebarFor, type Lang } from '../lib/lang';
import MobileSheet from '@cocoindex/brand/MobileSheet.astro';
export interface Props {
@@ -36,8 +36,14 @@ const {
sidebarItems: sidebarItemsRaw,
lang,
} = Astro.props;
+// Default: the docs sidebar of the page's language (the Python tree on pages
+// that are not docs pages, such as the home page and 404), so no link points
+// at a page that exists only in the other tree.
const sidebarItems: SidebarItem[] | null =
- sidebarItemsRaw === undefined ? sidebar : sidebarItemsRaw;
+ sidebarItemsRaw === undefined
+ ? sidebarFor(sidebar, lang ?? DEFAULT_LANG, await pageRegistry())
+ : sidebarItemsRaw;
+const isDocsTree = sidebarItemsRaw === undefined || lang !== undefined;
// Put the current section first without changing the shared desktop order.
function containsCurrent(item: SidebarItem): boolean {
return item.slug === currentSlug ||
@@ -106,7 +112,7 @@ function href(slug: string): string {
)}
<div class="mobile-pane" id="panePages" role={tocRows.length > 0 ? 'tabpanel' : undefined} aria-labelledby={tocRows.length > 0 ? 'tabPages' : undefined}>
- {(sidebarItems === sidebar || lang) && (
+ {isDocsTree && (
<div class="mobile-group">
<nav class="mobile-list" aria-label="Documentation home">
<a href={href('')} aria-current={currentSlug === '' ? 'page' : undefined}>
diff --git a/docs/src/content/docs/advanced_topics/index.mdx b/docs/src/content/docs/advanced_topics/index.mdx
index 6d96bc11..0a158ce1 100644
--- a/docs/src/content/docs/advanced_topics/index.mdx
+++ b/docs/src/content/docs/advanced_topics/index.mdx
@@ -5,25 +5,8 @@ description: >
running update, customize memoization, build live components, and connect
CocoIndex to systems it doesn't ship with.
---
-import DocCardGrid from '@cocoindex/brand/DocCardGrid.astro';
import { advancedTopicsGroups } from '/src/data/section-grids';
-{/* The card hrefs in section-grids.ts are root-relative Python URLs; the Rust copy points them at /docs/rust/. */}
-export const rustAdvancedTopicsGroups = advancedTopicsGroups.map((g) => ({
- ...g,
- cards: g.cards.map((c) => ({ ...c, href: c.href.replace(/^\/docs\//, '/docs/rust/') })),
-}));
-
You can build complete pipelines with the [programming guide](../programming_guide/core_concepts) alone. Reach for these pages when you want to go a level deeper into how the engine behaves, and extend it past what it ships with.
-<Lang only="python">
-
-<DocCardGrid groups={advancedTopicsGroups} ariaLabel="Advanced topics" />
-
-</Lang>
-
-<Lang only="rust">
-
-<DocCardGrid groups={rustAdvancedTopicsGroups} ariaLabel="Advanced topics" />
-
-</Lang>
+<LangCardGrid groups={advancedTopicsGroups} ariaLabel="Advanced topics" />
diff --git a/docs/src/content/docs/cli_commands.mdx b/docs/src/content/docs/cli_commands.mdx
deleted file mode 100644
index 77bc90cc..00000000
--- a/docs/src/content/docs/cli_commands.mdx
+++ /dev/null
@@ -1,144 +0,0 @@
----
-title: CLI *subcommands* reference
-description: >
- Reference for every `cocoindex` CLI subcommand β€” drop, init, ls, show, and
- update (catch-up or live) β€” with their arguments, flags, and app-target formats.
-languages: [python]
-rust_counterpart: cli
----
-## Subcommands reference
-
-### `drop`
-
-Drop an app and all its target states.
-
-This will:
-
-- Revert all target states created by the app (e.g., drop tables, delete rows)
-- Clear the app's internal state database
-
-`APP_TARGET`: `path/to/app.py`, `module`, `path/to/app.py:app_name`, or
-`module:app_name`.
-
-
-**Usage:**
-
-```bash
-cocoindex drop [OPTIONS] APP_TARGET
-```
-
-**Options:**
-
-| Option | Description |
-|--------|-------------|
-| `-f, --force` | Skip confirmation prompt. |
-| `-q, --quiet` | Avoid printing anything to the standard output, e.g. statistics. |
-| `--help` | Show this message and exit. |
-
----
-
-### `init`
-
-Initialize a new CocoIndex project.
-
-Creates a new project directory with starter files: 1. main.py (Main
-application file) 2. pyproject.toml (Project metadata and dependencies) 3.
-README.md (Quick start guide)
-
-`PROJECT_NAME`: Name of the project (defaults to current directory name if
-not specified).
-
-
-**Usage:**
-
-```bash
-cocoindex init [OPTIONS] [PROJECT_NAME]
-```
-
-**Options:**
-
-| Option | Description |
-|--------|-------------|
-| `--dir DIRECTORY` | Directory to create the project in. |
-| `--help` | Show this message and exit. |
-
----
-
-### `ls`
-
-List all apps.
-
-If `APP_TARGET` (`path/to/app.py` or `module`) is provided, lists apps
-defined in that module and their persisted status, grouped by environment.
-
-If `APP_TARGET` is omitted and `--db` is provided, lists all apps from the
-specified database.
-
-
-**Usage:**
-
-```bash
-cocoindex ls [OPTIONS] [APP_TARGET]
-```
-
-**Options:**
-
-| Option | Description |
-|--------|-------------|
-| `--db TEXT` | Path to database to list apps from (only used when APP_TARGET is not specified). |
-| `--help` | Show this message and exit. |
-
----
-
-### `show`
-
-Show the app's stable paths.
-
-If `APP_TARGET` is provided, loads the app from the module.
-Otherwise, `--db` and `--app-name` can be used to inspect an app
-directly from its database without loading the module.
-
-
-**Usage:**
-
-```bash
-cocoindex show [OPTIONS] [APP_TARGET]
-```
-
-**Options:**
-
-| Option | Description |
-|--------|-------------|
-| `--db TEXT` | Path to database (used with --app-name when APP_TARGET is not specified). |
-| `--app-name TEXT` | App name to inspect (used with --db when APP_TARGET is not specified). |
-| `--tree` | Display stable paths as a tree with component annotations. |
-| `--help` | Show this message and exit. |
-
----
-
-### `update`
-
-Run an app in catch-up mode. With --live, run in live mode.
-
-`APP_TARGET`: `path/to/app.py`, `module`, `path/to/app.py:app_name`, or
-`module:app_name`.
-
-
-**Usage:**
-
-```bash
-cocoindex update [OPTIONS] APP_TARGET
-```
-
-**Options:**
-
-| Option | Description |
-|--------|-------------|
-| `-f, --force` | Skip confirmation prompt. |
-| `-q, --quiet` | Avoid printing anything to the standard output, e.g. statistics. |
-| `--reset` | Drop existing setup before updating (equivalent to running 'cocoindex drop' first). |
-| `--full-reprocess` | Reprocess everything, bypassing all memoization caches: every component and memoized function executes again (external calls such as embeddings included). To force just one function's work to run again, bump its version= instead. |
-| `-L, --live` | Run in live mode (live components continue processing after initial update). |
-| `--help` | Show this message and exit. |
-
----
diff --git a/docs/src/content/docs/common_resources/index.mdx b/docs/src/content/docs/common_resources/index.mdx
index 7c9fdd16..4b41ee2b 100644
--- a/docs/src/content/docs/common_resources/index.mdx
+++ b/docs/src/content/docs/common_resources/index.mdx
@@ -4,20 +4,8 @@ description: >
Shared types and utilities used across connectors and operations: data models,
vector schema, stable ID generation, and the in-memory LiveMap.
---
-import DocCardGrid from '@cocoindex/brand/DocCardGrid.astro';
import { commonResourcesGroups } from '/src/data/section-grids';
-{/* The grid's hrefs point at the Python tree; the Rust page gets a copy that points at /docs/rust/. */}
-export const rustGroups = commonResourcesGroups.map((g) => ({
- ...g,
- cards: g.cards.map((c) => ({ ...c, href: c.href.replace(/^\/docs\//, '/docs/rust/') })),
-}));
-
The building blocks that connectors and operations share. Reach for these when you wire your own pieces together, or need the exact type a connector expects.
-<Lang only="python">
-<DocCardGrid groups={commonResourcesGroups} ariaLabel="Common resources" />
-</Lang>
-<Lang only="rust">
-<DocCardGrid groups={rustGroups} ariaLabel="Common resources" />
-</Lang>
+<LangCardGrid groups={commonResourcesGroups} ariaLabel="Common resources" />
diff --git a/docs/src/data/docs-sidebar.ts b/docs/src/data/docs-sidebar.ts
index 72d23c77..d3b879f7 100644
--- a/docs/src/data/docs-sidebar.ts
+++ b/docs/src/data/docs-sidebar.ts
@@ -97,6 +97,7 @@ export const sidebar: SidebarItem[] = [
{ type: 'doc', slug: 'ops', label: 'Overview' },
{ type: 'doc', slug: 'ops/entity_resolution', label: 'Entity resolution' },
{ type: 'doc', slug: 'ops/litellm', label: 'LiteLLM' },
+ { type: 'doc', slug: 'ops/model_apis', label: 'Model APIs' },
{ type: 'doc', slug: 'ops/sentence_transformers', label: 'Sentence transformers' },
{ type: 'doc', slug: 'ops/text', label: 'Text ops' },
],
diff --git a/docs/src/data/redirects.ts b/docs/src/data/redirects.ts
index 0b389d2a..ae343ded 100644
--- a/docs/src/data/redirects.ts
+++ b/docs/src/data/redirects.ts
@@ -93,4 +93,6 @@ export const redirects: Record<string, string> = {
'/rust': '/docs/rust/getting_started/overview/',
'/getting_started/rust_quickstart': '/docs/rust/getting_started/quickstart/',
'/cli_rust': '/docs/rust/cli/',
+ // An unused, outdated copy of the CLI subcommand reference.
+ '/cli_commands': '/docs/cli/',
};
diff --git a/docs/src/lib/lang.ts b/docs/src/lib/lang.ts
index 8fce19a1..6f3e98fb 100644
--- a/docs/src/lib/lang.ts
+++ b/docs/src/lib/lang.ts
@@ -78,8 +78,9 @@ export interface PageRegistry {
at(lang: Lang, route: string): PageEntry | undefined;
/** The page whose file slug is `fileSlug`. */
byFile(fileSlug: string): PageEntry | undefined;
- /** URL of the page a source link names (by file slug), in `lang`'s tree
- * when the page is there, else in the page's own language. */
+ /** URL of the page a source link names (by file slug): in `lang`'s tree
+ * when the page is there, else its declared counterpart in `lang`, else
+ * the page in its own language. */
resolve(target: string, lang: Lang): { href: string; lang: Lang; route: string } | undefined;
/** Where the language switch goes from `route` in `from` to `to`. */
switchTarget(from: Lang, route: string, to: Lang): string;
@@ -123,12 +124,16 @@ async function build(): Promise<PageRegistry> {
};
// A link names a file: it opens that file's page in the reader's language
- // when the page has one, else in the language it has.
+ // when the page has one, else the counterpart the page declares for that
+ // language, else the page in the language it has.
const resolve: PageRegistry['resolve'] = (target, lang) => {
const t = target.replace(/^\/+|\/+$/g, '');
const e = files.get(t);
if (!e) return undefined;
- const l = e.languages.includes(lang) ? lang : e.languages[0];
+ if (e.languages.includes(lang)) return { href: langHref(lang, e.route), lang, route: e.route };
+ const c = e.counterpart[lang];
+ if (c && at(lang, c)) return { href: langHref(lang, c), lang, route: c };
+ const l = e.languages[0];
return { href: langHref(l, e.route), lang: l, route: e.route };
};
diff --git a/docs/src/lib/llms.ts b/docs/src/lib/llms.ts
index bb8c05a5..43b28def 100644
--- a/docs/src/lib/llms.ts
+++ b/docs/src/lib/llms.ts
@@ -110,10 +110,6 @@ export async function llmsTxt(lang: Lang): Promise<string> {
// walkthroughs) in one file, for LLMs and agents that want everything in a
// single fetch. The llms.txt of the same language is the lighter index.
-// Include-fragments are embedded verbatim in their host page (cli.mdx inlines
-// cli_commands.mdx), so emitting them standalone would duplicate the content.
-const INCLUDE_FRAGMENTS = new Set(['cli_commands']);
-
export async function llmsFullTxt(lang: Lang): Promise<string> {
const reg = await pageRegistry();
const indexUrl = new URL(`${DOCS_BASE}/${langPrefix(lang)}llms.txt`, SITE_URL).toString();
@@ -131,12 +127,12 @@ export async function llmsFullTxt(lang: Lang): Promise<string> {
const seen = new Set<string>();
const emit = (route: string) => {
const e = reg.at(lang, route);
- if (!e || seen.has(route) || INCLUDE_FRAGMENTS.has(e.fileSlug)) return;
+ if (!e || seen.has(route)) return;
seen.add(route);
const data = e.doc.data as Record<string, unknown>;
const raw = lang === 'rust' && typeof data.rust_title === 'string' ? data.rust_title : e.doc.data.title;
const title = docTitle(e.doc.id, raw);
- out.push('', '---', '', `# ${title}`, '', `Source: ${langPageUrl(lang, route)}`, '', mdxToMarkdown(e.doc.body ?? '', docSrcDir(e.doc), lang));
+ out.push('', '---', '', `# ${title}`, '', `Source: ${langPageUrl(lang, route)}`, '', mdxToMarkdown(e.doc.body ?? '', docSrcDir(e.doc), lang, (s) => reg.resolve(s, lang)?.href));
};
// Sidebar order first, then any stray pages of the language not in the tree.
diff --git a/docs/src/lib/raw-markdown.ts b/docs/src/lib/raw-markdown.ts
index 194bccef..db8be79d 100644
--- a/docs/src/lib/raw-markdown.ts
+++ b/docs/src/lib/raw-markdown.ts
@@ -22,7 +22,7 @@
import { posix } from 'node:path';
import type { CollectionEntry } from 'astro:content';
import { getCollection, getEntry } from 'astro:content';
-import { DOCS_BASE, GITHUB_REPO, docSlug, docTitle, pageUrl, LLMS_TXT_URL, SKILL_MD_URL } from '../consts';
+import { DOCS_BASE, GITHUB_REPO, SITE_URL, docSlug, docTitle, pageUrl, LLMS_TXT_URL, SKILL_MD_URL } from '../consts';
import { findExample } from '../data/examples';
import { type Lang, DEFAULT_LANG, langPrefix, pageRegistry, stripOtherLanguage } from './lang';
import { FENCE, INLINE_CODE, MDX_COMMENT } from './fence.mjs';
@@ -62,9 +62,17 @@ const memo = import.meta.env.DEV ? null : new Map<string, string>();
// resolved against it and emitted as root-relative page URLs (/docs/<slug>/),
// the form remark-link-checker gives the HTML pages; the .md twins serve the
// body verbatim, and index pages sit one level shallower than their source.
-export function mdxToMarkdown(body: string, srcDir = '', lang?: Lang): string {
+// `pageHref` maps a linked page's file slug to its URL in the reader's
+// language tree (src/lib/lang.ts PageRegistry.resolve); without it, page links
+// go to the Python tree.
+export function mdxToMarkdown(
+ body: string,
+ srcDir = '',
+ lang?: Lang,
+ pageHref?: (fileSlug: string) => string | undefined,
+): string {
const key = `${lang ?? ''}\u0000${srcDir}\u0000${body ?? ''}`;
- const cached = memo?.get(key);
+ const cached = pageHref ? undefined : memo?.get(key);
if (cached !== undefined) return cached;
let s = (body ?? '').replace(/\r\n/g, '\n');
@@ -92,7 +100,8 @@ export function mdxToMarkdown(body: string, srcDir = '', lang?: Lang): string {
const [rel, frag] = target.split('#');
const path = posix.normalize(posix.join(srcDir, rel)).replace(/\/$/, '');
if (path.startsWith('..')) return m;
- return `](${DOCS_BASE}/${path}/${frag ? `#${frag}` : ''})`;
+ const href = pageHref?.(path.replace(/\/index$/, '')) ?? `${DOCS_BASE}/${path}/`;
+ return `](${href}${frag ? `#${frag}` : ''})`;
});
// 3. Flatten admonitions to a bold callout lead-in, keeping the body prose.
@@ -122,7 +131,7 @@ export function mdxToMarkdown(body: string, srcDir = '', lang?: Lang): string {
s = s.replace(RESTORE_FENCE, (_m, i) => fences[Number(i)]);
const out = s.trim();
- memo?.set(key, out);
+ if (!pageHref) memo?.set(key, out);
return out;
}
@@ -143,7 +152,16 @@ export async function docStaticPaths() {
// Shared top-of-page banner for every agent-facing .md twin: v1 guard, then
// source/index/skill pointers. One format for docs pages and example pages.
-function buildGuard(slug: string, lead: string, extra = ''): string {
+function buildGuard(slug: string, lead: string, extra = '', lang: Lang = DEFAULT_LANG): string {
+ if (lang === 'rust') {
+ return (
+ `> ${lead}\n` +
+ `>\n` +
+ `> Source: ${pageUrl(slug)} Β· Rust docs index: ${new URL(`${DOCS_BASE}/rust/llms.txt`, SITE_URL)}` +
+ ` Β· Rust SDK tour: ${GITHUB_REPO}/blob/main/rust/sdk/SHOWCASE.md` +
+ ` Β· Rust examples: ${GITHUB_REPO}/tree/main/examples/rust${extra}`
+ );
+ }
return (
`> ${lead}\n` +
`>\n` +
@@ -171,17 +189,27 @@ export function buildDocMarkdown(
doc: CollectionEntry<'docs'>,
lang: Lang = DEFAULT_LANG,
route: string = docSlug(doc.id),
+ pageHref?: (fileSlug: string) => string | undefined,
): string {
const data = doc.data as Record<string, unknown>;
const rustTitle = lang === 'rust' && typeof data.rust_title === 'string' ? data.rust_title : undefined;
const title = docTitle(doc.id, rustTitle ?? doc.data.title);
const slug = `${langPrefix(lang)}${route}`;
- const guard = buildGuard(
- slug,
- `**CocoIndex v1.** This page documents CocoIndex **v1** β€” a ground-up redesign ` +
- `from v0. When writing code, ignore any v0 flow-builder DSL or deprecated decorators.`,
- );
- return `# ${title}\n\n${guard}\n\n${mdxToMarkdown(doc.body, docSrcDir(doc), lang)}\n`;
+ const guard =
+ lang === 'rust'
+ ? buildGuard(
+ slug,
+ `**CocoIndex v1, Rust SDK.** This page documents the CocoIndex **v1** Rust SDK ` +
+ `(the \`cocoindex\` crate). The Python SDK pages are at ${new URL(`${DOCS_BASE}/`, SITE_URL)}.`,
+ '',
+ lang,
+ )
+ : buildGuard(
+ slug,
+ `**CocoIndex v1.** This page documents CocoIndex **v1** β€” a ground-up redesign ` +
+ `from v0. When writing code, ignore any v0 flow-builder DSL or deprecated decorators.`,
+ );
+ return `# ${title}\n\n${guard}\n\n${mdxToMarkdown(doc.body ?? '', docSrcDir(doc), lang, pageHref)}\n`;
}
// Full Markdown body for an example walkthrough's /examples/<slug>.md twin.
diff --git a/docs/src/middleware.ts b/docs/src/middleware.ts
index a167da93..8b1180af 100644
--- a/docs/src/middleware.ts
+++ b/docs/src/middleware.ts
@@ -31,8 +31,9 @@ export const onRequest = defineMiddleware(async (context, next) => {
}
const lang = slug.startsWith('rust/') ? 'rust' : 'python';
const route = lang === 'rust' ? slug.slice('rust/'.length) : slug;
- const entry = (await pageRegistry()).at(lang, route);
- if (entry) return markdown(buildDocMarkdown(entry.doc, lang, route));
+ const reg = await pageRegistry();
+ const entry = reg.at(lang, route);
+ if (entry) return markdown(buildDocMarkdown(entry.doc, lang, route, (s) => reg.resolve(s, lang)?.href));
}
return next();
});
diff --git a/docs/src/pages/[...slug].astro b/docs/src/pages/[...slug].astro
index 6d14f819..55606bbc 100644
--- a/docs/src/pages/[...slug].astro
+++ b/docs/src/pages/[...slug].astro
@@ -5,6 +5,7 @@ import LangLink from '../components/LangLink.astro';
import Lang from '../components/Lang.astro';
import LangTabs from '../components/LangTabs.astro';
import RustNote from '../components/RustNote.astro';
+import LangCardGrid from '../components/LangCardGrid.astro';
import { titleText } from '../consts';
import { docStaticPaths } from '../lib/raw-markdown';
import { headingsFor, pageEntry, type Lang } from '../lib/lang';
@@ -52,6 +53,6 @@ const { neutral } = pageEntry(doc);
sourcePath={sourcePath}
introMeta={introMeta}
>
- {/* Lang, LangTabs and RustNote need no import in a page. */}
- <Content components={{ a: LangLink, Lang, LangTabs, RustNote }} />
+ {/* Lang, LangTabs, RustNote and LangCardGrid need no import in a page. */}
+ <Content components={{ a: LangLink, Lang, LangTabs, RustNote, LangCardGrid }} />
</DocsLayout>
diff --git a/docs/src/pages/[...slug].md.ts b/docs/src/pages/[...slug].md.ts
index 63c64684..e7d46fa5 100644
--- a/docs/src/pages/[...slug].md.ts
+++ b/docs/src/pages/[...slug].md.ts
@@ -7,13 +7,14 @@
import type { APIRoute } from 'astro';
import { type CollectionEntry } from 'astro:content';
import { buildDocMarkdown, docStaticPaths } from '../lib/raw-markdown';
-import type { Lang } from '../lib/lang';
+import { pageRegistry, type Lang } from '../lib/lang';
export const getStaticPaths = docStaticPaths;
-export const GET: APIRoute = ({ props }) => {
+export const GET: APIRoute = async ({ props }) => {
const { doc, lang, route } = props as { doc: CollectionEntry<'docs'>; lang: Lang; route: string };
- return new Response(buildDocMarkdown(doc, lang, route), {
+ const reg = await pageRegistry();
+ return new Response(buildDocMarkdown(doc, lang, route, (s) => reg.resolve(s, lang)?.href), {
headers: { 'Content-Type': 'text/markdown; charset=utf-8' },
});
};
diff --git a/docs/src/pages/index.astro b/docs/src/pages/index.astro
index 3b3b9568..8e11ddb0 100644
--- a/docs/src/pages/index.astro
+++ b/docs/src/pages/index.astro
@@ -118,7 +118,7 @@ app.update_blocking()`;
<body class="docs-home">
<a class="skip-link" href="#main-content">Skip to content</a>
<Topbar mobileSheetId="mobileSheet" />
- <MobileSheet sidebarItems={sidebar} />
+ <MobileSheet lang="python" />
<div class="layout dh-layout">
<Sidebar currentSlug="" lang="python" />