Skip to content

Commit

Permalink
forgot to add two new files
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfiller committed Mar 7, 2021
1 parent 93c9547 commit 23555ed
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/components/content/series-navigator.svelte
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}
16 changes: 16 additions & 0 deletions src/routes/blog/series/[slug].json.js
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))
}

0 comments on commit 23555ed

Please sign in to comment.