File tree Expand file tree Collapse file tree 2 files changed +102
-0
lines changed
Expand file tree Collapse file tree 2 files changed +102
-0
lines changed Original file line number Diff line number Diff line change 1+ <script >
2+ import { getContext } from ' svelte'
3+ const series = getContext (' series' )
4+ let postIndex
5+ let previous
6+ let next
7+
8+ $: if (series) {
9+ postIndex = series .posts .findIndex (post => post .title === $$props .title )
10+ if (series .posts [postIndex - 1 ]) {
11+ previous = series .posts [postIndex - 1 ]
12+ }
13+ if (series .posts [postIndex + 1 ]) {
14+ next = series .posts [postIndex + 1 ]
15+ }
16+ }
17+ </script >
18+
19+ <style global type =' text/scss' >
20+ .series-navigator {
21+ & __title {
22+ color : var (--colorWhite );
23+ background : var (--colorHighlight );
24+ text-align : center ;
25+ padding : var (--padding );
26+ a {
27+ color : inherit ;
28+ & :not (:hover ) {
29+ text-decoration : none ;
30+ }
31+ }
32+ }
33+ & __buttons {
34+ background : var (--colorHighlight );
35+ display : flex ;
36+ }
37+ & __previous ,
38+ & __next {
39+ flex-wrap : wrap ;
40+ width : 50% ;
41+ & :before {
42+ font-size : .8em ;
43+ margin-bottom : calc (.5 * var (--padding ));
44+ display : block ;
45+ }
46+ }
47+ & __previous {
48+ text-align : right ;
49+ margin-right : auto ;
50+ & :before {
51+ content : ' « previous' ;
52+ }
53+ }
54+ & __next {
55+ text-align : left ;
56+ margin-left : auto ;
57+ & :before {
58+ content : ' next »' ;
59+ }
60+ }
61+ }
62+ </style >
63+
64+ {#if series }
65+ <aside class =' series-navigator__title' >
66+ This is post {postIndex + 1 } of {series .posts .length } in the <a href ={series .slug }>{series .title }</a > series.
67+ </aside >
68+
69+ <slot />
70+
71+ <aside class =' series-navigator__buttons' >
72+ {#if previous }
73+ <a href ={previous .slug } class =' series-navigator__previous button' >
74+ {previous .title }
75+ </a >
76+ {/if }
77+ {#if next }
78+ <a href ={next .slug } class =' series-navigator__next button' >
79+ {next .title }
80+ </a >
81+ {/if }
82+ </aside >
83+
84+ {:else }
85+ <slot />
86+ {/if }
Original file line number Diff line number Diff line change 1+
2+ import fetch from 'node-fetch'
3+
4+ export async function get ( req , res ) {
5+ res . writeHead ( 200 , {
6+ 'Content-Type' : 'application/json'
7+ } )
8+
9+ const slug = req . path . match ( / ( .* ) \. j s o n / ) [ 1 ]
10+
11+ const series = await fetch ( 'http://localhost:3000/blog/series.json' )
12+ . then ( response => response . json ( ) )
13+ . then ( series => series . find ( series => series . slug === slug ) )
14+
15+ res . end ( JSON . stringify ( series ) )
16+ }
You can’t perform that action at this time.
0 commit comments