├── .npmrc ├── static └── favicon.png ├── .gitignore ├── src ├── styles │ ├── reset.css │ └── globals.css ├── lib │ ├── prismicio.js │ └── nav.svelte ├── app.html └── routes │ ├── index.js │ ├── [uid].js │ ├── __layout.svelte │ ├── [uid].svelte │ └── index.svelte ├── netlify.toml ├── svelte.config.js ├── jsconfig.json ├── README.md └── package.json /.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | -------------------------------------------------------------------------------- /static/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/samlfair/svelte-tutorial/HEAD/static/favicon.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | -------------------------------------------------------------------------------- /src/styles/reset.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | } 5 | 6 | * { 7 | box-sizing: border-box; 8 | } 9 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "npm run build" 3 | publish = "build" 4 | 5 | [functions] 6 | node_bundler = "esbuild" -------------------------------------------------------------------------------- /svelte.config.js: -------------------------------------------------------------------------------- 1 | import adapter from '@sveltejs/adapter-auto'; 2 | 3 | /** @type {import('@sveltejs/kit').Config} */ 4 | const config = { 5 | kit: { 6 | adapter: adapter() 7 | } 8 | }; 9 | 10 | export default config; 11 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "$lib": ["src/lib"], 6 | "$lib/*": ["src/lib/*"] 7 | } 8 | }, 9 | "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"] 10 | } 11 | -------------------------------------------------------------------------------- /src/styles/globals.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | } 4 | 5 | .container { 6 | display: flex; 7 | flex-direction: column; 8 | align-items: center; 9 | padding: 0px 20px; 10 | } 11 | 12 | .container > * { 13 | width: 100%; 14 | max-width: 700px; 15 | } 16 | -------------------------------------------------------------------------------- /src/lib/prismicio.js: -------------------------------------------------------------------------------- 1 | import * as prismic from '@prismicio/client' 2 | 3 | // Update your repository name here 4 | const repositoryName = 'svelte-tutorial' 5 | 6 | const createClient = (params) => { 7 | return prismic.createClient(repositoryName, params) 8 | } 9 | 10 | export default createClient 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Svelte Tutorial Example Repo 2 | 3 | [See this project live](https://lucid-murdock-988f01.netlify.app/). 4 | 5 | Want to learn Svelte and SvelteKit? Check out [this tutorial](https://prismic.io/blog/svelte-sveltekit-tutorial). 6 | 7 | This repo is the final product of the above tutorial. It is a two-page website using Svelte and Sveltekit with content managed in Prismic. 8 | -------------------------------------------------------------------------------- /src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | %svelte.head% 9 | 10 | 11 |
%svelte.body%
12 | 13 | 14 | -------------------------------------------------------------------------------- /src/routes/index.js: -------------------------------------------------------------------------------- 1 | // ~/src/routes/index.js 2 | 3 | import createClient from '$lib/prismicio' 4 | 5 | export async function get({ fetch }) { 6 | const client = createClient({ fetch }) 7 | const document = await client.getByUID('page', 'homepage') 8 | 9 | if (document) 10 | return { 11 | body: { 12 | document, 13 | }, 14 | } 15 | 16 | return { 17 | status: 404, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/routes/[uid].js: -------------------------------------------------------------------------------- 1 | // ~/src/routes/[uid]].js 2 | 3 | import createClient from '$lib/prismicio' 4 | 5 | export async function get({ fetch, params }) { 6 | const client = createClient({ fetch }) 7 | const { uid } = params 8 | const document = await client.getByUID('page', uid) 9 | 10 | if (document) 11 | return { 12 | body: { 13 | document, 14 | }, 15 | } 16 | 17 | return { 18 | status: 404, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/lib/nav.svelte: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "svelte-kit-app", 3 | "version": "0.0.1", 4 | "scripts": { 5 | "dev": "svelte-kit dev", 6 | "build": "svelte-kit build", 7 | "package": "svelte-kit package", 8 | "preview": "svelte-kit preview" 9 | }, 10 | "devDependencies": { 11 | "@sveltejs/adapter-auto": "next", 12 | "@sveltejs/adapter-netlify": "^1.0.0-next.46", 13 | "@sveltejs/kit": "next", 14 | "svelte": "^3.44.0" 15 | }, 16 | "type": "module", 17 | "dependencies": { 18 | "@prismicio/client": "^6.3.0", 19 | "@prismicio/helpers": "^2.1.1" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/routes/__layout.svelte: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 |
10 |
11 |
13 | 14 | 15 |
16 | 17 | 35 | -------------------------------------------------------------------------------- /src/routes/[uid].svelte: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 |
10 |
11 |

12 | {document.data.title} 13 |

14 |
15 |
16 |
17 | {@html prismicH.asHTML(document.data.content)} 18 |
19 |
20 |
21 | 22 | -------------------------------------------------------------------------------- /src/routes/index.svelte: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 |
10 |
11 |

12 | {document.data.title} 13 |

14 |
15 |
16 |
17 | {@html prismicH.asHTML(document.data.content)} 18 |
19 |
20 |
21 | 22 | --------------------------------------------------------------------------------