switch to directly importing post, and install static adapter
This commit is contained in:
parent
d0aaba7a7d
commit
af6b065de8
14
package-lock.json
generated
14
package-lock.json
generated
@ -5,9 +5,9 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "blog",
|
||||
"version": "0.0.1",
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-static": "^1.0.0-next.21",
|
||||
"@sveltejs/kit": "next",
|
||||
"mdsvex": "^0.9.8",
|
||||
"svelte": "^3.42.6"
|
||||
@ -26,6 +26,12 @@
|
||||
"node": ">= 8.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@sveltejs/adapter-static": {
|
||||
"version": "1.0.0-next.21",
|
||||
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-1.0.0-next.21.tgz",
|
||||
"integrity": "sha512-B4+QoUVAaANKx+mHntG8SqF45zbj3Ct4Akg/cGauo6COyfKZRhO5OsMa+wPuT2TKJBZC4eEDK0p+p9nyQBkxKQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@sveltejs/kit": {
|
||||
"version": "1.0.0-next.184",
|
||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.184.tgz",
|
||||
@ -675,6 +681,12 @@
|
||||
"picomatch": "^2.2.2"
|
||||
}
|
||||
},
|
||||
"@sveltejs/adapter-static": {
|
||||
"version": "1.0.0-next.21",
|
||||
"resolved": "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-1.0.0-next.21.tgz",
|
||||
"integrity": "sha512-B4+QoUVAaANKx+mHntG8SqF45zbj3Ct4Akg/cGauo6COyfKZRhO5OsMa+wPuT2TKJBZC4eEDK0p+p9nyQBkxKQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@sveltejs/kit": {
|
||||
"version": "1.0.0-next.184",
|
||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.184.tgz",
|
||||
|
@ -7,6 +7,7 @@
|
||||
"preview": "svelte-kit preview"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-static": "^1.0.0-next.21",
|
||||
"@sveltejs/kit": "next",
|
||||
"mdsvex": "^0.9.8",
|
||||
"svelte": "^3.42.6"
|
||||
|
@ -3,18 +3,18 @@
|
||||
let post = await import(`./_posts/${page.params.slug}.svx`);
|
||||
return {
|
||||
props: {
|
||||
metadata: post.metadata,
|
||||
BlogPost: post.default
|
||||
meta: post.metadata,
|
||||
body: post.default
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export let metadata, BlogPost;
|
||||
export let meta, body;
|
||||
</script>
|
||||
|
||||
<div id="post">
|
||||
<h1>{metadata.title}</h1>
|
||||
<svelte:component this={BlogPost} />
|
||||
<h1>{meta.title}</h1>
|
||||
<svelte:component this={body} />
|
||||
</div>
|
||||
|
@ -33,7 +33,7 @@
|
||||
<nav id="nav-main">
|
||||
<a href="/">Home</a>
|
||||
<a href="/posts">Posts</a>
|
||||
<a href="/about">About</a>
|
||||
<a href="#">About</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
@ -2,8 +2,8 @@ const posts = import.meta.globEager('./_posts/*.svx');
|
||||
export let postData = [];
|
||||
|
||||
for (const path in posts) {
|
||||
const urlPath = path.slice(8, -4)
|
||||
posts[path].metadata.path = urlPath;
|
||||
const slug = path.slice(9, -4)
|
||||
posts[path].metadata.slug = slug;
|
||||
postData.push(posts[path].metadata);
|
||||
}
|
||||
postData.sort((a, b) => {
|
||||
|
@ -1,11 +0,0 @@
|
||||
import { postData } from './all.json.js';
|
||||
const path = postData[0].path;
|
||||
|
||||
export async function get({ host }) {
|
||||
const resp = await fetch(`http://${host}${path}`);
|
||||
return {
|
||||
status: resp.status,
|
||||
headers: {'Content-Type': 'text/html'},
|
||||
body: await resp.text()
|
||||
}
|
||||
}
|
20
src/routes/index.svelte
Normal file
20
src/routes/index.svelte
Normal file
@ -0,0 +1,20 @@
|
||||
<script context="module">
|
||||
export async function load({ fetch }) {
|
||||
const resp = await fetch('/all.json');
|
||||
const allPosts = (await resp.json());
|
||||
const post = await import(`./_posts/${allPosts[0].slug}.svx`);
|
||||
return {
|
||||
props: {
|
||||
meta: post.metadata,
|
||||
body: post.default,
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import BlogPost from './[slug].svelte';
|
||||
export let meta, body;
|
||||
</script>
|
||||
|
||||
<BlogPost {meta} {body}></BlogPost>
|
@ -1,6 +1,6 @@
|
||||
<script context="module">
|
||||
export async function load({ page, fetch }) {
|
||||
const resp = await fetch(`http://${page.host}/all.json`);
|
||||
const resp = await fetch('/all.json');
|
||||
return {
|
||||
props: {
|
||||
postData: await resp.json()
|
||||
@ -31,7 +31,7 @@
|
||||
<h1>All Posts</h1>
|
||||
{#each postData as post}
|
||||
<p>
|
||||
<a class="post-link" href="{post.path}"><h3>{post.title}</h3></a>
|
||||
<a class="post-link" href="/{post.slug}"><h3>{post.title}</h3></a>
|
||||
</p>
|
||||
{/each}
|
||||
</div>
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { mdsvex } from "mdsvex";
|
||||
import { mdsvex } from 'mdsvex';
|
||||
import staticAdapter from '@sveltejs/adapter-static';
|
||||
|
||||
|
||||
const config = {
|
||||
@ -6,7 +7,8 @@ const config = {
|
||||
preprocess: mdsvex(),
|
||||
kit: {
|
||||
// hydrate the <div id="svelte"> element in src/app.html
|
||||
target: '#svelte'
|
||||
target: '#svelte',
|
||||
adapter: staticAdapter(),
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user