Skip to content

Commit c895c94

Browse files
Merge pull request #2678 from appwrite/fix-docs-404
2 parents 5e20f60 + 288ae8a commit c895c94

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

bun.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"lockfileVersion": 1,
3+
"configVersion": 0,
34
"workspaces": {
45
"": {
56
"name": "appwrite-website",

src/hooks.server.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,36 @@ import * as Sentry from '@sentry/sveltekit';
22
import type { Handle } from '@sveltejs/kit';
33
import redirects from './redirects.json';
44
import { sequence } from '@sveltejs/kit/hooks';
5+
import { getMarkdownContent } from '$lib/server/markdown';
56
import { type GithubUser } from '$routes/(init)/init/(utils)/auth';
67
import { createInitSessionClient } from '$routes/(init)/init/(utils)/appwrite';
78
import type { AppwriteUser } from '$lib/utils/console';
89

910
const redirectMap = new Map(redirects.map(({ link, redirect }) => [link, redirect]));
1011

12+
const markdownHandler: Handle = async ({ event, resolve }) => {
13+
const pathname = event.url.pathname;
14+
if (!pathname.endsWith('.md')) {
15+
return resolve(event);
16+
}
17+
18+
// strip trailing ".md" from the pathname to get the underlying route id
19+
const withoutExt = pathname.replace(/\.md$/, '');
20+
const routeId = withoutExt;
21+
22+
const content = await getMarkdownContent(routeId);
23+
if (content == null) {
24+
return new Response('Not found', { status: 404 });
25+
}
26+
27+
return new Response(content, {
28+
status: 200,
29+
headers: {
30+
'Content-Type': 'text/markdown; charset=utf-8'
31+
}
32+
});
33+
};
34+
1135
const redirecter: Handle = async ({ event, resolve }) => {
1236
const currentPath = event.url.pathname;
1337
if (redirectMap.has(currentPath)) {
@@ -200,6 +224,7 @@ const initSession: Handle = async ({ event, resolve }) => {
200224

201225
export const handle = sequence(
202226
Sentry.sentryHandle(),
227+
markdownHandler,
203228
redirecter,
204229
wwwRedirecter,
205230
securityheaders,

src/routes/[...slug]/+server.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)