Skip to content

Commit 90378c0

Browse files
committed
Add preliminary support for section listing
1 parent 8d8dac3 commit 90378c0

File tree

15 files changed

+152
-27
lines changed

15 files changed

+152
-27
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
]
1111
],
1212
"plugins": [
13-
"@babel/plugin-proposal-optional-chaining"
13+
"@babel/plugin-proposal-optional-chaining",
1414
]
1515
}

data/osa-1/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ path: "/osa-1"
33
title: "Osa 1"
44
---
55

6-
Tässä osassa käyt läpi
6+
Tässä osassa opit kirjoittamaan ohjelmia, jotka lukevat käyttäjältä syötettä ja tekevät laskentaa syötteen perusteella. Opit käsitteet muuttuja, ehtolause ja toistolause, ja opit käyttämään näitä ohjelmissasi.
77

8-
* Tulostus
9-
* Muuttujat
10-
* Laskentaa
8+
<pages-in-this-section></pages-in-this-section>
9+
10+
Osa on tarkoitus suorittaa viikon aikana.

data/osa-2/1-ratkaisumalleja.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
---
22
path: "/osa-2/1-ratkaisumalleja"
3-
title: "Osa 2"
3+
title: "Ratkaisumalleja"
44
---
55

6-
76
<% partial 'partials/hint', locals: { name: 'Ensimmäisen osan tavoitteet' } do %>
87

98
<p>

data/osa-2/2-jotakin-muuta.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
path: "/osa-2/2-muuta"
3+
title: "Jotakin muuta"
4+
---
5+
6+
Lolled

data/osa-2/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ path: "/osa-2"
33
title: "Osa 2"
44
---
55

6-
Osa 2 on paras
6+
Tässä osassa opit paljon.
7+
8+
<pages-in-this-section>

package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"react-helmet": "^5.2.0",
1818
"react-motion": "^0.5.2",
1919
"react-scrollspy": "^3.3.5",
20+
"rehype-react": "^3.1.0",
2021
"styled-components": "^4.1.1",
2122
"typeface-open-sans-condensed": "0.0.54"
2223
},
@@ -33,6 +34,7 @@
3334
"devDependencies": {
3435
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
3536
"babel-preset-gatsby": "^0.1.4",
37+
"import-all.macro": "^2.0.3",
3638
"prettier": "^1.15.2"
3739
}
3840
}

src/components/Sidebar.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class Sidebar extends React.Component {
4949
const edges =
5050
this.props.data?.allMarkdownRemark?.edges.map(o => o.node?.frontmatter) || []
5151
const content = content2.concat(edges)
52-
console.log(JSON.stringify(edges))
5352
return (
5453
<SidebarContainer>
5554
<TopContainer>

src/contexes/PagesContext.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import React from "react";
2+
3+
export default React.createContext()

src/partials/PagesInThisSection.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react'
2+
import PagesContext from '../contexes/PagesContext'
3+
import { nthIndex } from '../util/strings'
4+
import { Link } from 'gatsby'
5+
6+
export default () => (
7+
<PagesContext.Consumer>
8+
{value => {
9+
const currentPath = value.current.path
10+
let sectionPath = currentPath
11+
const sectionSeparator = nthIndex(currentPath, '/', 2)
12+
if (sectionSeparator !== -1) {
13+
sectionPath = currentPath.substr(0, sectionSeparator)
14+
}
15+
16+
const sectionPages = value.all.filter(o =>
17+
o.path.startsWith(`${sectionPath}/`)
18+
)
19+
20+
return (
21+
<div>
22+
<b>Tässä osassa:</b>
23+
{sectionPages.map((page, i) => (
24+
<div key={page.path}>
25+
{i + 1}. <Link to={page.path}>{page.title}</Link>
26+
</div>
27+
))}
28+
</div>
29+
)
30+
}}
31+
</PagesContext.Consumer>
32+
)

0 commit comments

Comments
 (0)