The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix TOC highlight
Joshen Lim5a917682ebfe
diff --git a/apps/docs/components/CustomHTMLElements/Heading.tsx b/apps/docs/components/CustomHTMLElements/Heading.tsxindex b07ea6cab17..43c78865d63 100644--- a/apps/docs/components/CustomHTMLElements/Heading.tsx+++ b/apps/docs/components/CustomHTMLElements/Heading.tsx@@ -6,16 +6,21 @@ import {} from './CustomHTMLElements.utils'import { useInView } from 'react-intersection-observer'+/**+ * [Joshen] The trick with rootMargin+ * We are shrinking the top of the root element by 20 percent, which is currently our entire page,+ * and the bottom by 35 percent. Therefore, when a header is at the top 20 percent and bottom 35 percent+ * of our page, it will not be counted as visible.+ */+const Heading = ({ tag, children }) => {const HeadingTag = `${tag}` as anyconst anchor = getAnchor(children)const link = `#${anchor}`- // check if current heading is in view, update TOC active item accordingly- // [Joshen] Ideally we highlight the section in the TOC when it's at the top of the page- // much like when we click on the item in the TOC itself, the rootMargin fix is insufficientconst { ref } = useInView({threshold: 1,+ rootMargin: '-20% 0% -35% 0px',onChange: (inView, entry) => {if (window.scrollY === 0) unHighlightSelectedTocItems()if (inView) highlightSelectedTocItem(entry.target.id)diff --git a/apps/docs/components/GuidesTableOfContents.tsx b/apps/docs/components/GuidesTableOfContents.tsxindex 83872a1ff6b..9d25121f661 100644--- a/apps/docs/components/GuidesTableOfContents.tsx+++ b/apps/docs/components/GuidesTableOfContents.tsx@@ -52,22 +52,6 @@ const GuidesTableOfContents: FC<Props> = ({ list }) => {</li>))}</ul>-- // <ul className="toc-menu list-none pl-4 text-[0.8rem] grid gap-2 mt-12">- // {(toc.json as TOCHeader[])- // .filter((item) => item.lvl !== 1 && item.lvl <= 3)- // .map((item: any, i: number) => {- // return (- // <li key={i} id={item.lvl} style={{ marginLeft: `${(item.lvl - 2) * 1}rem` }}>- // <a- // href={`#${formatSlug(item.slug)}`}- // className="text-scale-1000 hover:text-brand-900 transition-colors"- // dangerouslySetInnerHTML={{ __html: formatTOCHeader(removeAnchor(item.content)) }}- // />- // </li>- // )- // })}- // </ul>)}