get footer links working and get rid of unnecessary json route

This commit is contained in:
Joseph Montanaro 2023-08-27 08:52:30 -07:00
parent 1b2d55173a
commit a28ee8b2f0
6 changed files with 30 additions and 13 deletions

View File

@ -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,
}

View 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,
};
}

View File

@ -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;
}
}

View 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,
};
}

View File

@ -1,3 +1,4 @@
import { writable } from 'svelte/store';
import { dev } from '$app/environment';
const posts = import.meta.globEager('./*.svx');

View File

@ -1,7 +0,0 @@
import { json } from '@sveltejs/kit';
import { postData } from '../_posts/all.js';
export async function GET() {
return json(postData[0]);
}