diff --git a/bun.lock b/bun.lock index 87c8e58356..3bf3646614 100644 --- a/bun.lock +++ b/bun.lock @@ -1,5 +1,6 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "appwrite-website", diff --git a/src/hooks.server.ts b/src/hooks.server.ts index e4de7281fe..a75880c745 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -2,12 +2,36 @@ import * as Sentry from '@sentry/sveltekit'; import type { Handle } from '@sveltejs/kit'; import redirects from './redirects.json'; import { sequence } from '@sveltejs/kit/hooks'; +import { getMarkdownContent } from '$lib/server/markdown'; import { type GithubUser } from '$routes/(init)/init/(utils)/auth'; import { createInitSessionClient } from '$routes/(init)/init/(utils)/appwrite'; import type { AppwriteUser } from '$lib/utils/console'; const redirectMap = new Map(redirects.map(({ link, redirect }) => [link, redirect])); +const markdownHandler: Handle = async ({ event, resolve }) => { + const pathname = event.url.pathname; + if (!pathname.endsWith('.md')) { + return resolve(event); + } + + // strip trailing ".md" from the pathname to get the underlying route id + const withoutExt = pathname.replace(/\.md$/, ''); + const routeId = withoutExt; + + const content = await getMarkdownContent(routeId); + if (content == null) { + return new Response('Not found', { status: 404 }); + } + + return new Response(content, { + status: 200, + headers: { + 'Content-Type': 'text/markdown; charset=utf-8' + } + }); +}; + const redirecter: Handle = async ({ event, resolve }) => { const currentPath = event.url.pathname; if (redirectMap.has(currentPath)) { @@ -200,6 +224,7 @@ const initSession: Handle = async ({ event, resolve }) => { export const handle = sequence( Sentry.sentryHandle(), + markdownHandler, redirecter, wwwRedirecter, securityheaders, diff --git a/src/routes/[...slug]/+server.ts b/src/routes/[...slug]/+server.ts deleted file mode 100644 index bfc31a0243..0000000000 --- a/src/routes/[...slug]/+server.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { RequestHandler } from './$types'; -import { getMarkdownContent } from '$lib/server/markdown'; - -export const GET: RequestHandler = async ({ params, url }) => { - const pathname = url.pathname; - if (!pathname.endsWith('.md')) { - return new Response('Not found', { status: 404 }); - } - - const slug = params.slug; - if (!slug) { - return new Response('Not found', { status: 404 }); - } - - // strip trailing ".md" from the slug to get the underlying route id - const withoutExt = slug.replace(/\.md$/, ''); - const routeId = `/${withoutExt}`; - - const content = await getMarkdownContent(routeId); - if (content == null) { - return new Response('Not found', { status: 404 }); - } - - return new Response(content, { - status: 200, - headers: { - 'Content-Type': 'text/markdown; charset=utf-8' - } - }); -};