get footer links working and get rid of unnecessary json route
This commit is contained in:
parent
1b2d55173a
commit
a28ee8b2f0
@ -1,7 +1,6 @@
|
||||
export async function load({ fetch }) {
|
||||
const resp = await fetch('/latest');
|
||||
const postMeta = await resp.json();
|
||||
const post = await import(`./_posts/${postMeta.slug}.svx`);
|
||||
export async function load({ data }) {
|
||||
let post = await import(`./_posts/${data.slug}.svx`);
|
||||
post.metadata.next = data.next;
|
||||
return {
|
||||
post: post.default,
|
||||
}
|
||||
|
11
src/routes/+page.server.js
Normal file
11
src/routes/+page.server.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { postData, siblingPosts } from './_posts/all.js';
|
||||
|
||||
|
||||
// this is in a "servserside" loader so that we don't end up embedding the metadata
|
||||
// for every post into the final page
|
||||
export function load() {
|
||||
return {
|
||||
slug: postData[0].slug,
|
||||
next: postData[1].slug,
|
||||
};
|
||||
}
|
@ -1,14 +1,17 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
|
||||
export async function load({ url, params }) {
|
||||
export async function load({ url, params, data }) {
|
||||
try {
|
||||
let post = await import(`../_posts/${params.slug}.svx`);
|
||||
post.metadata.prev = data.prev;
|
||||
post.metadata.next = data.next;
|
||||
return {
|
||||
post: post.default,
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
throw error(404, `Not found: ${url.pathname}`);
|
||||
// throw error(404, `Not found: ${url.pathname}`);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
10
src/routes/[slug]/+page.server.js
Normal file
10
src/routes/[slug]/+page.server.js
Normal file
@ -0,0 +1,10 @@
|
||||
import { postData } from '../_posts/all.js';
|
||||
|
||||
|
||||
export function load({ params }) {
|
||||
const i = postData.findIndex(p => p.slug === params.slug);
|
||||
return {
|
||||
prev: i > 0 ? postData[i - 1].slug : null,
|
||||
next: i < postData.length - 1 ? postData[i + 1].slug : null,
|
||||
};
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { dev } from '$app/environment';
|
||||
const posts = import.meta.globEager('./*.svx');
|
||||
|
||||
|
@ -1,7 +0,0 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { postData } from '../_posts/all.js';
|
||||
|
||||
|
||||
export async function GET() {
|
||||
return json(postData[0]);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user