on master help sign in
grants: strip h3s
1d77c15Matilde Park
components/TableOfContents.js+5−4
@@ -1,7 +1,7 @@
1import { useState, useEffect, useRef } from "react";
1import { useState, useEffect, useRef } from "react";
2
2
3−export const TableOfContents = ({ staticPosition }) => {
3+export const TableOfContents = ({ staticPosition, noh3s }) => {
4− const { nestedHeadings } = useHeadingsData();
4+ const { nestedHeadings } = useHeadingsData(noh3s);
5 const [activeId, setActiveId] = useState();
5 const [activeId, setActiveId] = useState();
6 useIntersectionObserver(setActiveId);
6 useIntersectionObserver(setActiveId);
7 return (
7 return (
@@ -36,11 +36,12 @@ const getNestedHeadings = (headingElements) => {
36 return nestedHeadings;
36 return nestedHeadings;
37};
37};
38
38
39−const useHeadingsData = () => {
39+const useHeadingsData = (noh3s) => {
40 const [nestedHeadings, setNestedHeadings] = useState([]);
40 const [nestedHeadings, setNestedHeadings] = useState([]);
41
41
42+ const query = noh3s ? "h2" : "h2, h3";
42 useEffect(() => {
43 useEffect(() => {
43− const headingElements = Array.from(document.querySelectorAll("h2, h3"));
44+ const headingElements = Array.from(document.querySelectorAll(query));
44
45
45 const newNestedHeadings = getNestedHeadings(headingElements);
46 const newNestedHeadings = getNestedHeadings(headingElements);
46 setNestedHeadings(newNestedHeadings);
47 setNestedHeadings(newNestedHeadings);
pages/grants.js+1−1
@@ -137,7 +137,7 @@ export default function Grants({
137 at urbit.org, Tlon developers, and community mentors.
137 at urbit.org, Tlon developers, and community mentors.
138 </p>
138 </p>
139 </div>
139 </div>
140− <TableOfContents staticPosition />
140+ <TableOfContents staticPosition noh3s />
141 </div>
141 </div>
142 <div className="p-8 bg-wall flex flex-col w-full rounded-lg space-y-4">
142 <div className="p-8 bg-wall flex flex-col w-full rounded-lg space-y-4">
143 <p>
143 <p>