Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions bun.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"lockfileVersion": 1,
"configVersion": 0,
"workspaces": {
"": {
"name": "appwrite-website",
Expand Down
25 changes: 25 additions & 0 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -200,6 +224,7 @@ const initSession: Handle = async ({ event, resolve }) => {

export const handle = sequence(
Sentry.sentryHandle(),
markdownHandler,
redirecter,
wwwRedirecter,
securityheaders,
Expand Down
30 changes: 0 additions & 30 deletions src/routes/[...slug]/+server.ts

This file was deleted.