diff --git a/src/components/SistentNavigation/intra-page.js b/src/components/SistentNavigation/intra-page.js index 6c74497a95bbb0..dd098b2b7e9cae 100644 --- a/src/components/SistentNavigation/intra-page.js +++ b/src/components/SistentNavigation/intra-page.js @@ -60,14 +60,22 @@ const JoinCommunityWrapper = styled.div` } `; -function IntraPage() { - const [contents, setContents] = useState([]); +function IntraPage({ contents: providedContents }) { + const [scannedContents, setScannedContents] = useState([]); + + // Pages that build their own layout pass an explicit list of sections. + // Pages rendered through the MDX template instead expose their sections + // as anchors inside `.main-content`, which are discovered here. + const hasProvidedContents = Boolean(providedContents && providedContents.length); useEffect(() => { + if (hasProvidedContents) { + return; + } const anchors = document.querySelectorAll(".main-content > a"); console.log(anchors); if (anchors) { - setContents( + setScannedContents( Array.from(anchors).map((a) => ({ id: a.id, link: `#${a.id}`, @@ -75,7 +83,9 @@ function IntraPage() { })) ); } - }, []); + }, [hasProvidedContents]); + + const contents = hasProvidedContents ? providedContents : scannedContents; const [intapath, setIntapath] = useState(null); useEffect(() => { diff --git a/src/sections/Projects/Sistent/getting-started/about/index.js b/src/sections/Projects/Sistent/getting-started/about/index.js index 7acf547dc94cc6..dd2c224f07022a 100644 --- a/src/sections/Projects/Sistent/getting-started/about/index.js +++ b/src/sections/Projects/Sistent/getting-started/about/index.js @@ -10,7 +10,11 @@ import { useStyledDarkMode } from "../../../../../theme/app/useStyledDarkMode"; import CodeBlock from "../../../../../components/CodeBlock"; import { SistentThemeProvider, Button } from "@sistent/sistent"; -const contents = [{ id: 0, link: "#About Sistent", text: "About Sistent" }]; +const contents = [ + { id: 0, link: "#About Sistent", text: "About Sistent" }, + { id: 1, link: "#Installation", text: "Installation" }, + { id: 2, link: "#Using local Sistent", text: "Using local Sistent" }, +]; const codes = [ "npm i @sistent/sistent",