-
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 series navigator STILL WRITE TESTS
- Loading branch information
1 parent
e939c36
commit d58c989
Showing
18 changed files
with
217 additions
and
31 deletions.
There are no files selected for viewing
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,86 @@ | ||
<script> | ||
import { getContext } from 'svelte' | ||
const series = getContext('series') | ||
let postIndex | ||
let previous | ||
let next | ||
$: if (series) { | ||
postIndex = series.posts.findIndex(post => post.title === $$props.title) | ||
if (series.posts[postIndex - 1]) { | ||
previous = series.posts[postIndex - 1] | ||
} | ||
if (series.posts[postIndex + 1]) { | ||
next = series.posts[postIndex + 1] | ||
} | ||
} | ||
</script> | ||
|
||
<style global type='text/scss'> | ||
.series-navigator { | ||
&__title { | ||
color: var(--colorWhite); | ||
background: var(--colorHighlight); | ||
text-align: center; | ||
padding: var(--padding); | ||
a { | ||
color: inherit; | ||
&:not(:hover) { | ||
text-decoration: none; | ||
} | ||
} | ||
} | ||
&__buttons { | ||
background: var(--colorHighlight); | ||
display: flex; | ||
} | ||
&__previous, | ||
&__next { | ||
flex-wrap: wrap; | ||
width: 50%; | ||
&:before { | ||
font-size: .8em; | ||
margin-bottom: calc(.5 * var(--padding)); | ||
display: block; | ||
} | ||
} | ||
&__previous { | ||
text-align: right; | ||
margin-right: auto; | ||
&:before { | ||
content: '« previous'; | ||
} | ||
} | ||
&__next { | ||
text-align: left; | ||
margin-left: auto; | ||
&:before { | ||
content: 'next »'; | ||
} | ||
} | ||
} | ||
</style> | ||
|
||
{#if series} | ||
<aside class='series-navigator__title'> | ||
This is post {postIndex + 1} of {series.posts.length} in the <a href={series.slug}>{series.title}</a> series. | ||
</aside> | ||
|
||
<slot /> | ||
|
||
<aside class='series-navigator__buttons'> | ||
{#if previous} | ||
<a href={previous.slug} class='series-navigator__previous button'> | ||
{previous.title} | ||
</a> | ||
{/if} | ||
{#if next} | ||
<a href={next.slug} class='series-navigator__next button'> | ||
{next.title} | ||
</a> | ||
{/if} | ||
</aside> | ||
|
||
{:else} | ||
<slot /> | ||
{/if} |
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<script> | ||
import Page from './page.svelte' | ||
import Markdown from '../components/layout/markdown.svelte' | ||
import SeriesNavigator from '../components/blog/series-navigator.svelte' | ||
</script> | ||
|
||
<Page {...$$props} > | ||
<Markdown> | ||
<slot /> | ||
</Markdown> | ||
<SeriesNavigator {...$$props}> | ||
<Markdown> | ||
<slot /> | ||
</Markdown> | ||
</SeriesNavigator> | ||
</Page> |
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,32 @@ | ||
<script context='module'> | ||
export async function preload(page) { | ||
const { slug } = page.params | ||
const component = await import(`./_content/${slug}/index.md`) | ||
const series = await this.fetch(`/blog/series.json`) | ||
.then(response => response.json()) | ||
.then(allSeries => allSeries.find(series => { | ||
const postSlugs = series.posts.map(series => series.slug.replace('/blog/', '')) | ||
if (postSlugs.includes(slug)) { | ||
return series | ||
} | ||
})) | ||
return { | ||
page: component.default, | ||
metadata: component.metadata, | ||
series: series | ||
} | ||
} | ||
</script> | ||
|
||
<script> | ||
export let page | ||
export let series | ||
import { setContext } from 'svelte' | ||
setContext('series', series) | ||
</script> | ||
|
||
<svelte:component this={page} /> |
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,16 @@ | ||
|
||
import fetch from 'node-fetch' | ||
|
||
export async function get(req, res) { | ||
res.writeHead(200, { | ||
'Content-Type': 'application/json' | ||
}) | ||
|
||
const slug = req.path.match(/(.*)\.json/)[1] | ||
|
||
const series = await fetch('http://localhost:3000/blog/series.json') | ||
.then(response => response.json()) | ||
.then(series => series.find(series => series.slug === slug)) | ||
|
||
res.end(JSON.stringify(series)) | ||
} |
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
Oops, something went wrong.