diff --git a/app/middleware/content.ts b/app/middleware/content.ts new file mode 100644 index 0000000..46e1a42 --- /dev/null +++ b/app/middleware/content.ts @@ -0,0 +1,21 @@ +import { parseMarkdown } from "@nuxtjs/mdc/runtime"; + +export default defineNuxtRouteMiddleware(async (to) => { + const supabase = useSupabaseClient(); + + const { data } = await supabase + .from("content") + .select("md") + .eq("slug", to.path) + .maybeSingle(); + if (data) { + const { md } = data; + const ast = await parseMarkdown(md); + to.meta.ast = ast; + } else { + return abortNavigation({ + statusCode: 404, + message: "ツ", + }); + } +}); diff --git a/app/pages/[...slug].vue b/app/pages/[...slug].vue index b8fd05c..3217c52 100644 --- a/app/pages/[...slug].vue +++ b/app/pages/[...slug].vue @@ -1,34 +1,19 @@