website/src/routes/+page.server.ts

22 lines
585 B
TypeScript
Raw Normal View History

2022-11-10 00:12:34 +05:30
import type { PageServerLoad } from "./$types";
2022-11-29 21:12:15 +05:30
import { compile } from "mdsvex";
2023-01-06 02:11:28 +05:30
import sanitizeHtml from "sanitize-html";
import db from "$lib/db";
2022-11-10 00:12:34 +05:30
export const load: PageServerLoad = async () => {
const Announcements = db.model("Announcements");
const data = await Announcements.findAll().then((docs) => {
return docs.map((doc) => doc.get());
});
2023-01-06 02:11:28 +05:30
const sanitizedContent = sanitizeHtml(data[0].title)
if (data.length !== 0 || data[0] !== undefined) {
return {
announcements: data[0],
2023-01-06 02:11:28 +05:30
content: compile(sanitizedContent).then((compiled) => compiled?.code)
}
}
2022-12-27 20:58:47 +05:30
};