@@ -17,6 +17,7 @@ import LoginStateContext, {
1717import Container from "../components/Container"
1818
1919import { loggedIn } from "../services/moocfi"
20+ import { NoSsr } from "@material-ui/core"
2021
2122const ContentWrapper = styled . div `
2223 margin-top: 1rem;
@@ -29,6 +30,21 @@ const ContentWrapper = styled.div`
2930
3031const Title = styled . h1 ``
3132
33+ const Titled = ( { level, children } ) => {
34+ if ( level === 1 ) {
35+ return < h1 > { children } </ h1 >
36+ }
37+ if ( level === 2 ) {
38+ return < h4 > { children } </ h4 >
39+ }
40+ if ( level === 3 ) {
41+ return < h5 > { children } </ h5 >
42+ }
43+ if ( level === 4 ) {
44+ return < h6 > { children } </ h6 >
45+ }
46+ }
47+
3248export default class CoursePartOverviewTemplate extends React . Component {
3349 static contextType = LoginStateContext
3450
@@ -72,6 +88,37 @@ export default class CoursePartOverviewTemplate extends React.Component {
7288 < ContentWrapper >
7389 < Title > { frontmatter . title } </ Title >
7490 { renderAst ( htmlAst ) }
91+ < NoSsr >
92+ < h1 > Otsikot</ h1 >
93+ < div >
94+ { data . allPages . edges
95+ . filter ( page =>
96+ page . node . frontmatter . path . startsWith (
97+ document . location . pathname + "/" ,
98+ ) ,
99+ )
100+ . sort ( ( a , b ) => {
101+ a = a . node . frontmatter . path . toLowerCase ( )
102+ b = b . node . frontmatter . path . toLowerCase ( )
103+
104+ return a > b ? 1 : b > a ? - 1 : 0
105+ } )
106+ . map ( ( page , i ) => (
107+ < div >
108+ < h2 >
109+ { i } : { page . node . frontmatter . title }
110+ </ h2 >
111+ { page . node . headings . map ( heading => {
112+ return (
113+ < Titled level = { heading . depth } >
114+ { heading . value } ({ heading . depth } )
115+ </ Titled >
116+ )
117+ } ) }
118+ </ div >
119+ ) ) }
120+ </ div >
121+ </ NoSsr >
75122 </ ContentWrapper >
76123 </ Container >
77124 </ Fragment >
@@ -105,6 +152,10 @@ export const pageQuery = graphql`
105152 type
106153 parentPagePath
107154 }
155+ headings {
156+ value
157+ depth
158+ }
108159 }
109160 }
110161 }
0 commit comments