@@ -2,12 +2,36 @@ import * as Sentry from '@sentry/sveltekit';
22import type { Handle } from '@sveltejs/kit' ;
33import redirects from './redirects.json' ;
44import { sequence } from '@sveltejs/kit/hooks' ;
5+ import { getMarkdownContent } from '$lib/server/markdown' ;
56import { type GithubUser } from '$routes/(init)/init/(utils)/auth' ;
67import { createInitSessionClient } from '$routes/(init)/init/(utils)/appwrite' ;
78import type { AppwriteUser } from '$lib/utils/console' ;
89
910const 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 ( / \. m d $ / , '' ) ;
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+
1135const 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
201225export const handle = sequence (
202226 Sentry . sentryHandle ( ) ,
227+ markdownHandler ,
203228 redirecter ,
204229 wwwRedirecter ,
205230 securityheaders ,
0 commit comments