on master help sign in
grants: strip h3s
commit1d77c15312a5fe71bbbc202801ac11ce78d667be authorMatilde Park <matilde@tlon.io> dateTue 27 Jul 2021, 23:09 (5 years ago) parent7726700
2 files changed+6−5
components/TableOfContents.js+5−4 pages/grants.js+1−1
components/TableOfContents.js+5−4
@@ -1,7 +1,7 @@
11import { useState, useEffect, useRef } from "react";
22
3−export const TableOfContents = ({ staticPosition }) => {
4− const { nestedHeadings } = useHeadingsData();
3+export const TableOfContents = ({ staticPosition, noh3s }) => {
4+ const { nestedHeadings } = useHeadingsData(noh3s);
55 const [activeId, setActiveId] = useState();
66 useIntersectionObserver(setActiveId);
77 return (
@@ -36,11 +36,12 @@ const getNestedHeadings = (headingElements) => {
3636 return nestedHeadings;
3737};
3838
39−const useHeadingsData = () => {
39+const useHeadingsData = (noh3s) => {
4040 const [nestedHeadings, setNestedHeadings] = useState([]);
4141
42+ const query = noh3s ? "h2" : "h2, h3";
4243 useEffect(() => {
43− const headingElements = Array.from(document.querySelectorAll("h2, h3"));
44+ const headingElements = Array.from(document.querySelectorAll(query));
4445
4546 const newNestedHeadings = getNestedHeadings(headingElements);
4647 setNestedHeadings(newNestedHeadings);
pages/grants.js+1−1
@@ -137,7 +137,7 @@ export default function Grants({
137137 at urbit.org, Tlon developers, and community mentors.
138138 </p>
139139 </div>
140− <TableOfContents staticPosition />
140+ <TableOfContents staticPosition noh3s />
141141 </div>
142142 <div className="p-8 bg-wall flex flex-col w-full rounded-lg space-y-4">
143143 <p>