Skip to content

handle doc 404s #4084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sites/kit.svelte.dev/src/lib/docs/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const type_regex = new RegExp(
* @param {string} dir
* @param {string} file
*/
export async function read_file(dir, file) {
async function read_file(dir, file) {
const match = /\d{2}-(.+)\.md/.exec(file);
if (!match) return null;

Expand Down
28 changes: 28 additions & 0 deletions sites/kit.svelte.dev/src/routes/docs/[slug].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { mode, prerendering } from '$app/env';
import { read } from '$lib/docs/server';

/** @type {import('@sveltejs/kit').RequestHandler} */
export async function get({ params }) {
// TODO https://github.com/sveltejs/kit/issues/4093
if (!prerendering && mode === 'production') {
return { status: 404 };
}

const page = await read('docs', params.slug);

if (!page) {
return { status: 404 };
}

return {
body: {
prev: page.prev,
next: page.next,
section: {
file: page.section.file,
title: page.section.title,
content: page.section.content
}
}
};
}
18 changes: 0 additions & 18 deletions sites/kit.svelte.dev/src/routes/docs/[slug].json.js

This file was deleted.

15 changes: 0 additions & 15 deletions sites/kit.svelte.dev/src/routes/docs/[slug].svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
<script context="module">
export const prerender = true;

// TODO should use a shadow endpoint instead, need to fix a bug first
/** @type {import('@sveltejs/kit').Load} */
export async function load({ fetch, params }) {
const res = await fetch(`/docs/${params.slug}.json`);
const { prev, next, section } = await res.json();

return {
props: {
prev,
next,
section
}
};
}
</script>

<script>
Expand Down