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,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "blog",
|
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@sveltejs/adapter-static": "^1.0.0-next.21",
|
||||||
"@sveltejs/kit": "next",
|
"@sveltejs/kit": "next",
|
||||||
"mdsvex": "^0.9.8",
|
"mdsvex": "^0.9.8",
|
||||||
"svelte": "^3.42.6"
|
"svelte": "^3.42.6"
|
||||||
@ -26,6 +26,12 @@
|
|||||||
"node": ">= 8.0.0"
|
"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": {
|
"node_modules/@sveltejs/kit": {
|
||||||
"version": "1.0.0-next.184",
|
"version": "1.0.0-next.184",
|
||||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.184.tgz",
|
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.184.tgz",
|
||||||
@ -675,6 +681,12 @@
|
|||||||
"picomatch": "^2.2.2"
|
"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": {
|
"@sveltejs/kit": {
|
||||||
"version": "1.0.0-next.184",
|
"version": "1.0.0-next.184",
|
||||||
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.184.tgz",
|
"resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-1.0.0-next.184.tgz",
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"preview": "svelte-kit preview"
|
"preview": "svelte-kit preview"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@sveltejs/adapter-static": "^1.0.0-next.21",
|
||||||
"@sveltejs/kit": "next",
|
"@sveltejs/kit": "next",
|
||||||
"mdsvex": "^0.9.8",
|
"mdsvex": "^0.9.8",
|
||||||
"svelte": "^3.42.6"
|
"svelte": "^3.42.6"
|
||||||
|
@ -3,18 +3,18 @@
|
|||||||
let post = await import(`./_posts/${page.params.slug}.svx`);
|
let post = await import(`./_posts/${page.params.slug}.svx`);
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
metadata: post.metadata,
|
meta: post.metadata,
|
||||||
BlogPost: post.default
|
body: post.default
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export let metadata, BlogPost;
|
export let meta, body;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="post">
|
<div id="post">
|
||||||
<h1>{metadata.title}</h1>
|
<h1>{meta.title}</h1>
|
||||||
<svelte:component this={BlogPost} />
|
<svelte:component this={body} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
<nav id="nav-main">
|
<nav id="nav-main">
|
||||||
<a href="/">Home</a>
|
<a href="/">Home</a>
|
||||||
<a href="/posts">Posts</a>
|
<a href="/posts">Posts</a>
|
||||||
<a href="/about">About</a>
|
<a href="#">About</a>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@ const posts = import.meta.globEager('./_posts/*.svx');
|
|||||||
export let postData = [];
|
export let postData = [];
|
||||||
|
|
||||||
for (const path in posts) {
|
for (const path in posts) {
|
||||||
const urlPath = path.slice(8, -4)
|
const slug = path.slice(9, -4)
|
||||||
posts[path].metadata.path = urlPath;
|
posts[path].metadata.slug = slug;
|
||||||
postData.push(posts[path].metadata);
|
postData.push(posts[path].metadata);
|
||||||
}
|
}
|
||||||
postData.sort((a, b) => {
|
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">
|
<script context="module">
|
||||||
export async function load({ page, fetch }) {
|
export async function load({ page, fetch }) {
|
||||||
const resp = await fetch(`http://${page.host}/all.json`);
|
const resp = await fetch('/all.json');
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
postData: await resp.json()
|
postData: await resp.json()
|
||||||
@ -31,7 +31,7 @@
|
|||||||
<h1>All Posts</h1>
|
<h1>All Posts</h1>
|
||||||
{#each postData as post}
|
{#each postData as post}
|
||||||
<p>
|
<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>
|
</p>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { mdsvex } from "mdsvex";
|
import { mdsvex } from 'mdsvex';
|
||||||
|
import staticAdapter from '@sveltejs/adapter-static';
|
||||||
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
@ -6,7 +7,8 @@ const config = {
|
|||||||
preprocess: mdsvex(),
|
preprocess: mdsvex(),
|
||||||
kit: {
|
kit: {
|
||||||
// hydrate the <div id="svelte"> element in src/app.html
|
// 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