File tree Expand file tree Collapse file tree 3 files changed +56
-3
lines changed
packages/cursorless-org-docs
src/docs/user/languages/components Expand file tree Collapse file tree 3 files changed +56
-3
lines changed Original file line number Diff line number Diff line change 11// @ts -check
22
33/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig } */
4- const sidebars = {
4+ export default {
55 user : [ { type : "autogenerated" , dirName : "user" } ] ,
66 contributing : [ { type : "autogenerated" , dirName : "contributing" } ] ,
77} ;
8-
9- export default sidebars ;
Original file line number Diff line number Diff line change 1+ import { useEffect } from "react" ;
2+
3+ export default function DynamicTOC ( ) {
4+ useEffect ( ( ) => {
5+ const row = document . querySelector ( "main .row" ) ;
6+
7+ if ( row == null ) {
8+ console . error ( "No row found in the main element" ) ;
9+ return ;
10+ }
11+
12+ row . appendChild ( getTOC ( ) ) ;
13+ } , [ ] ) ;
14+
15+ return null ;
16+ }
17+
18+ function getTOC ( ) {
19+ const headingElements = Array . from ( document . querySelectorAll ( "h3" ) ) . map (
20+ ( el ) => ( {
21+ id : el . id ,
22+ text : el . textContent ?. replace ( "#" , "" ) ?? "" ,
23+ } ) ,
24+ ) ;
25+
26+ const col = document . createElement ( "div" ) ;
27+ col . className = "col col--3" ;
28+
29+ const toc = document . createElement ( "div" ) ;
30+ toc . className = "tableOfContents_tkZC thin-scrollbar" ;
31+ toc . style . position = "fixed" ;
32+ toc . style . right = "1rem" ;
33+ toc . style . width = "14rem" ;
34+ col . appendChild ( toc ) ;
35+
36+ const ul = document . createElement ( "ul" ) ;
37+ ul . className = "table-of-contents table-of-contents__left-border" ;
38+ toc . appendChild ( ul ) ;
39+
40+ headingElements . forEach ( ( h ) => {
41+ const li = document . createElement ( "li" ) ;
42+
43+ const a = document . createElement ( "a" ) ;
44+ a . href = `#${ h . id } ` ;
45+ a . className = "table-of-contents__link" ;
46+ a . textContent = h . text ;
47+
48+ li . appendChild ( a ) ;
49+ ul . appendChild ( li ) ;
50+ } ) ;
51+
52+ return col ;
53+ }
Original file line number Diff line number Diff line change 11import React from "react" ;
2+ import DynamicTOC from "./DynamicTOC" ;
23import { ScopeSupport } from "./ScopeSupport" ;
34
45interface Props {
@@ -8,6 +9,7 @@ interface Props {
89export function Language ( { languageId } : Props ) {
910 return (
1011 < >
12+ < DynamicTOC />
1113 < ScopeSupport languageId = { languageId } />
1214 </ >
1315 ) ;
You can’t perform that action at this time.
0 commit comments