-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move md data fetching logic to middleware
- Loading branch information
1 parent
c90fe33
commit db8be5d
Showing
2 changed files
with
29 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "ツ", | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters