mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-15 04:14:46 +00:00
36 lines
711 B
HTML
36 lines
711 B
HTML
<svelte:head>
|
|
<title>{post.title}</title>
|
|
</svelte:head>
|
|
|
|
<h1>{post.title}</h1>
|
|
|
|
<div class='content'>
|
|
{@html post.html}
|
|
</div>
|
|
|
|
<script>
|
|
export default {
|
|
preload({ params, query }) {
|
|
// the `slug` parameter is available because this file
|
|
// is called [slug].html
|
|
const { slug } = params;
|
|
|
|
if (slug === 'throw-an-error') {
|
|
return this.error(500, 'something went wrong');
|
|
}
|
|
|
|
return fetch(`blog/${slug}.json`).then(r => {
|
|
if (r.status === 200) {
|
|
return r.json().then(post => ({ post }));
|
|
this.error(r.status, '')
|
|
}
|
|
|
|
if (r.status === 404) {
|
|
this.error(404, 'Not found');
|
|
} else {
|
|
throw new Error('Something went wrong');
|
|
}
|
|
});
|
|
}
|
|
};
|
|
</script> |