Skip to content

Commit b1a2643

Browse files
hesreallyhimReally Him
andauthored
[DOC]: Fix broken Next/Prev link buttons (#4310)
## Description of changes Fixes #4215 On certain pages, specifically those that had a top section with no subsection, the Next/Prev functionality was sometimes breaking. This was due to the way the links and the slugs were connected and from the configuration of the Sidebar and the its components. ## Fixes It turns out that `path` can be computed from `slug` by just prepending a `/`, so I removed the `path` property and refactored it to add some small logic to convert slug to path, simplifying the component properties. In addition, I found that some links to the python-thin-client were broken, due to using relative paths, so I just did a quick fix by using the absolute path instead. The only downside is that if you are working in an IDE, the absolute link won't work within the IDE. There are ways to patch this, or configure editors to find the right path, if people think this is worth addressing. ## Test plan *How are these changes tested?* Run the app locally, validate the cases that are mentioned as breaking in the Issue referenced above are working now, check other links for sanity, check links to python-thin-clint, check links to "Edit this page on GitHub". Built the app locally and no failures or problems. - [ ] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust ## Documentation Changes *Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs repository](https://github.com/chroma-core/docs)?* --------- Co-authored-by: Really Him <[email protected]>
1 parent c7d01a4 commit b1a2643

File tree

11 files changed

+37
-31
lines changed

11 files changed

+37
-31
lines changed

docs/docs.trychroma.com/components/markdoc/markdoc-renderer.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,41 +31,41 @@ const MarkdocRenderer: React.FC<{ slug: string[] }> = ({ slug }) => {
3131
function extractToc(ast) {
3232
// @ts-expect-error - This is a private function
3333
const toc = [];
34-
34+
3535
// @ts-expect-error - This is a private function
3636
function traverse(node) {
3737
if (!node) return;
38-
38+
3939
if (node.type === "heading") {
4040
const title = node.children[0].children[0].attributes.content;
4141
const id =
4242
node.attributes.id ||
4343
title.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, ""); // Generate an ID if missing
44-
44+
4545
toc.push({
4646
level: node.attributes.level, // Heading level (1, 2, 3...)
4747
title: title.trim(),
4848
id: id.trim(),
4949
});
5050
}
51-
51+
5252
// Recursively traverse children
5353
if (node.children) {
5454
for (const child of node.children) {
5555
traverse(child);
5656
}
5757
}
5858
}
59-
59+
6060
traverse(ast);
6161
// @ts-expect-error - This is a private function
6262
return toc;
6363
}
64-
64+
6565
// Extracts text recursively from children nodes
6666
// function extractText(node) {
6767
// if (!node || !node.children) return "";
68-
68+
6969
// return node.children
7070
// .map((child) => {
7171
// if (child.type === "text") return child.content || ""; // Direct text content
@@ -100,12 +100,12 @@ const MarkdocRenderer: React.FC<{ slug: string[] }> = ({ slug }) => {
100100
{output}
101101
<div className="flex items-center justify-between mt-5">
102102
{prev ? (
103-
<PageNav path={prev.path || ""} name={prev.name} type="prev" />
103+
<PageNav slug={prev.slug || ""} name={prev.name} type="prev" />
104104
) : (
105105
<div />
106106
)}
107107
{next ? (
108-
<PageNav path={next.path || ""} name={next.name} type="next" />
108+
<PageNav slug={next.slug || ""} name={next.name} type="next" />
109109
) : (
110110
<div />
111111
)}
@@ -137,4 +137,3 @@ const MarkdocRenderer: React.FC<{ slug: string[] }> = ({ slug }) => {
137137
};
138138

139139
export default MarkdocRenderer;
140-

docs/docs.trychroma.com/components/markdoc/page-nav.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
import React from "react";
44
import Link from "next/link";
55
import { ArrowLeft, ArrowRight } from "lucide-react";
6+
import { slugToPath } from "@/lib/content";
67

78
const PageNav: React.FC<{
8-
path: string;
9+
slug: string;
910
name: string;
1011
type: "prev" | "next";
11-
}> = ({ path, name, type }) => {
12+
}> = ({ slug, name, type }) => {
1213
return (
1314
<Link
14-
href={path}
15+
href={slugToPath(slug)}
1516
onClick={() => {
1617
sessionStorage.removeItem("sidebarScrollPosition");
1718
}}

docs/docs.trychroma.com/components/sidebar/page-index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const playfairDisplay = Playfair_Display({
1010
});
1111

1212
const PageIndex: React.FC<{
13-
path: string;
13+
basePath: string;
1414
pages: { id: string; name: string }[];
1515
name?: string;
1616
index: number;
17-
}> = ({ path, pages, name, index }) => {
17+
}> = ({ basePath, pages, name, index }) => {
1818
const className = index === 0 ? "" : "border-t-2 pt-6 dark:border-t-gray-700";
1919

2020
return (
@@ -34,7 +34,7 @@ const PageIndex: React.FC<{
3434
<PageLink
3535
id={page.id}
3636
name={page.name}
37-
path={`${path}/${page.id}`}
37+
slug={`${basePath}/${page.id}`}
3838
sectionPage={name !== undefined}
3939
/>
4040
</Suspense>

docs/docs.trychroma.com/components/sidebar/page-link.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33
import React from "react";
44
import Link from "next/link";
55
import { usePathname, useSearchParams } from "next/navigation";
6+
import { slugToPath } from "@/lib/content";
67

78
const PageLink: React.FC<{
89
id: string;
910
name: string;
10-
path: string;
11+
slug: string;
1112
sectionPage: boolean;
12-
}> = ({ id, name, path, sectionPage = true }) => {
13+
}> = ({ id, name, slug, sectionPage = true }) => {
1314
const pathName = usePathname();
1415
const searchParams = useSearchParams();
16+
const path = slugToPath(slug);
1517
const active = pathName === path;
1618
const lang = searchParams?.get("lang");
1719

docs/docs.trychroma.com/components/sidebar/sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const Sidebar: React.FC<{ path: string[]; mobile?: boolean }> = ({
6666
{currentSection.pages && (
6767
<div className="flex flex-col gap-2">
6868
<PageIndex
69-
path={`/${currentSection.id}`}
69+
basePath={`${currentSection.id}`}
7070
pages={currentSection.pages}
7171
index={0}
7272
/>
@@ -77,7 +77,7 @@ const Sidebar: React.FC<{ path: string[]; mobile?: boolean }> = ({
7777
key={subsection.id}
7878
index={index}
7979
name={subsection.name}
80-
path={`/${currentSection.id}/${subsection.id}`}
80+
basePath={`${currentSection.id}/${subsection.id}`}
8181
pages={
8282
subsection.generatePages
8383
? generatePages([currentSection.id, subsection.id])

docs/docs.trychroma.com/lib/content.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export interface AppPage {
44
id: string;
55
name: string;
66
slug?: string;
7-
path?: string;
87
}
98

109
export interface AppSection {
@@ -31,21 +30,21 @@ export const getAllPages = (sidebarConfig: AppSection[], sectionId: string) => {
3130

3231
pages.push(
3332
...(section.pages?.map((page) => {
33+
const pageSlug = `${section.id}/${page.id}`;
3434
return {
3535
...page,
36-
slug: `${section.id}/${page.id}`,
37-
path: `./${page.slug}`,
36+
slug: pageSlug,
3837
};
3938
}) || []),
4039
);
4140

4241
section.subsections?.forEach((subsection) => {
4342
pages.push(
4443
...(subsection.pages?.map((page) => {
44+
const pageSlug = `${section.id}/${subsection.id}/${page.id}`;
4545
return {
4646
...page,
47-
slug: `${section.id}/${subsection.id}/${page.id}`,
48-
path: `../${subsection.id}/${page.id}`,
47+
slug: pageSlug,
4948
};
5049
}) || []),
5150
);
@@ -54,6 +53,11 @@ export const getAllPages = (sidebarConfig: AppSection[], sectionId: string) => {
5453
return pages;
5554
};
5655

56+
// Helper function to convert slug to path
57+
export const slugToPath = (slug: string): string => {
58+
return `/${slug}`;
59+
};
60+
5761
export const getPagePrevNext = (
5862
slug: string[],
5963
pages: AppPage[],

docs/docs.trychroma.com/markdoc/content/production/chroma-server/client-server-mode.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def main():
3838
asyncio.run(main())
3939
```
4040

41-
If you intend to deploy your Chroma server, you may want to consider our [thin-client package](./thin-client) for client-side interactions.
41+
If you intend to deploy your Chroma server, you may want to consider our [thin-client package](/production/chroma-server/python-thin-client) for client-side interactions.
4242

4343
{% /Tab %}
4444

@@ -57,4 +57,4 @@ const client = new ChromaClient();
5757

5858
{% /Tab %}
5959

60-
{% /Tabs %}
60+
{% /Tabs %}

docs/docs.trychroma.com/markdoc/content/production/cloud-providers/aws.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ aws cloudformation create-stack --stack-name my-chroma-stack --template-url http
138138

139139
Once your EC2 instance is up and running with Chroma, all
140140
you need to do is configure your `HttpClient` to use the server's IP address and port
141-
`8000`. Since you are running a Chroma server on AWS, our [thin-client package](../chroma-server/python-thin-client) may be enough for your application.
141+
`8000`. Since you are running a Chroma server on AWS, our [thin-client package](/production/chroma-server/python-thin-client) may be enough for your application.
142142

143143
{% TabbedCodeBlock %}
144144

docs/docs.trychroma.com/markdoc/content/production/cloud-providers/azure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ terraform output -raw public_ip_address
9999

100100
Once your Azure VM instance is up and running with Chroma, all
101101
you need to do is configure your `HttpClient` to use the server's IP address and port
102-
`8000`. Since you are running a Chroma server on Azure, our [thin-client package](../chroma-server/python-thin-client) may be enough for your application.
102+
`8000`. Since you are running a Chroma server on Azure, our [thin-client package](/production/chroma-server/python-thin-client) may be enough for your application.
103103

104104
{% TabbedCodeBlock %}
105105

docs/docs.trychroma.com/markdoc/content/production/cloud-providers/gcp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ terraform output -raw chroma_instance_ip
126126

127127
Once your Compute Engine instance is up and running with Chroma, all
128128
you need to do is configure your `HttpClient` to use the server's IP address and port
129-
`8000`. Since you are running a Chroma server on GCP, our [thin-client package](../chroma-server/python-thin-client) may be enough for your application.
129+
`8000`. Since you are running a Chroma server on GCP, our [thin-client package](/production/chroma-server/python-thin-client) may be enough for your application.
130130

131131
{% TabbedCodeBlock %}
132132

0 commit comments

Comments
 (0)