-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preliminary support for section listing
- Loading branch information
Showing
15 changed files
with
152 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
] | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-optional-chaining" | ||
"@babel/plugin-proposal-optional-chaining", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
path: "/osa-2/2-muuta" | ||
title: "Jotakin muuta" | ||
--- | ||
|
||
Lolled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ path: "/osa-2" | |
title: "Osa 2" | ||
--- | ||
|
||
Osa 2 on paras | ||
Tässä osassa opit paljon. | ||
|
||
<pages-in-this-section> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import React from "react"; | ||
|
||
export default React.createContext() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react' | ||
import PagesContext from '../contexes/PagesContext' | ||
import { nthIndex } from '../util/strings' | ||
import { Link } from 'gatsby' | ||
|
||
export default () => ( | ||
<PagesContext.Consumer> | ||
{value => { | ||
const currentPath = value.current.path | ||
let sectionPath = currentPath | ||
const sectionSeparator = nthIndex(currentPath, '/', 2) | ||
if (sectionSeparator !== -1) { | ||
sectionPath = currentPath.substr(0, sectionSeparator) | ||
} | ||
|
||
const sectionPages = value.all.filter(o => | ||
o.path.startsWith(`${sectionPath}/`) | ||
) | ||
|
||
return ( | ||
<div> | ||
<b>Tässä osassa:</b> | ||
{sectionPages.map((page, i) => ( | ||
<div key={page.path}> | ||
{i + 1}. <Link to={page.path}>{page.title}</Link> | ||
</div> | ||
))} | ||
</div> | ||
) | ||
}} | ||
</PagesContext.Consumer> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react' | ||
import PagesContext from '../contexes/PagesContext' | ||
|
||
export default () => ( | ||
<PagesContext.Consumer>{value => <div>{JSON.stringify(value)}</div>}</PagesContext.Consumer> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import React from 'react' | ||
|
||
export default () => <div>This is test 2.</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import importAll from 'import-all.macro' | ||
const partials = importAll.sync('./*.js') | ||
|
||
const namedPartials = {} | ||
|
||
Object.entries(partials) | ||
.filter(([k, _]) => k !== './index.js') | ||
.forEach(([k, v]) => { | ||
const newKey = toKebabCase(k.replace('./', '').replace('.js', '')) | ||
namedPartials[newKey] = v.default | ||
}) | ||
|
||
function toKebabCase(string) { | ||
return string.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase() | ||
} | ||
|
||
export default namedPartials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export function nthIndex(str, pat, n){ | ||
var L= str.length, i= -1; | ||
while(n-- && i++<L){ | ||
i= str.indexOf(pat, i); | ||
if (i < 0) break; | ||
} | ||
return i; | ||
} |