Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SvelteKitでJamstackを試す

 SvelteKitでJamstackを試す

ジャムジャム!!Jamstack_2【初心者歓迎LT会】での資料です。

Kazuki Shibata

October 28, 2021
Tweet

More Decks by Kazuki Shibata

Other Decks in Programming

Transcript

  1. UTϑΝΠϧʹΑΔ"1*ͷఆٛྫ import db from '$lib/database' ; /* * * @type

    {import('@sveltejs/kit').RequestHandler } */ export async function get({ params }) { // the `slug` parameter is available because this file // is called [slug].json.js const { slug } = params ; const article = await db.get(slug) ; if (article) { return { body: { articl e } } ; } }
  2. -PBEؔ਺ʢ/FYUKTͷHFU4UBUJD1SPQT૬౰ͷ΋ͷʣ <script context="module"> export async function load({ page, fetch, session,

    stuff }) { const url = `/blog/${page.params.slug}.json` ; const res = await fetch(url) ; if (res.ok) { return { props: { article: await res.json( ) } } ; } return { status: res.status , error: new Error(`Could not load ${url}` ) } ; } </script>
  3.  Ϗϧυ࣌ɺ41"ભҠ࣌ʹಈ࡞͢Δ  UTϑΝΠϧʹͯ੩తԽͨ͠+40/ Λऔಘ͠ʹ͍͘ͷ͕௨ྫͬΆ͍  ड͚औͬͨ΋ͷΛςϯϓϨʔτଆʹ ౉ͯ͠දࣔͷྲྀΕ  MFUʹҧ࿨ײ

    -PBE͔ΒͷදࣔͷྲྀΕ <script context="module"> export function load({ error, status }) { return { props: { title: `${status}: ${error.message}` } } ; } </script> <script> export let title ; </script> <h1>{title}</h1>