Last active
June 12, 2021 02:59
-
-
Save kuc-arc-f/1e3f19734249417f95676b1002c6d7cd to your computer and use it in GitHub Desktop.
sveltekit sample, cms display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Config from '../../../app_config' | |
// GET /xxx.json | |
export const get = async (request) => { | |
var cfg = Config.get_config() | |
const res = await fetch( cfg.MY_JSON_URL); | |
const posts = await res.json(); | |
if (res.status === 404) { | |
return { body: [] }; | |
} | |
var ret = { | |
status : 200, | |
body : posts, | |
} | |
return ret; | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script context="module"> | |
import { enhance } from '$lib/form'; | |
import Config from '../../../app_config' | |
// see https://kit.svelte.dev/docs#loading | |
export const load = async ({ fetch }) => { | |
const res = await fetch('/posts.json'); | |
if (res.ok) { | |
const posts = await res.json(); | |
return { | |
props: { posts: posts.items } | |
}; | |
} | |
const { message } = await res.json(); | |
return { | |
error: new Error(message) | |
}; | |
}; | |
</script> | |
<script> | |
import { scale } from 'svelte/transition'; | |
import { flip } from 'svelte/animate'; | |
export let posts; | |
//var cfg = Config.get_config() | |
// console.log(cfg) | |
</script> | |
<style> | |
.body_wrap{ position:relative; } | |
.badge_post{ | |
position:absolute; top:-15px; left:10px; | |
} | |
</style> | |
<svelte:head> | |
<title>Posts</title> | |
</svelte:head> | |
<!-- --> | |
<div class="body_main_wrap"> | |
<h1>Posts</h1> | |
<hr /> | |
{#each posts as item} | |
<a href={`/posts/${item.save_id}`}><h3>{item.title}</h3> | |
</a> | |
ID : {item.id} | |
<a href={`/posts/${item.save_id}`} class="btn">[ show ] | |
</a> | |
<hr /> | |
{/each} | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment