Skip to content

Commit

Permalink
feat(Blog Slug): ✨ Back to using Node.js markdown parser
Browse files Browse the repository at this point in the history
  • Loading branch information
bKoZii committed Sep 20, 2024
1 parent 53dd118 commit ae71c01
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions pages/blog/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
<BlogSlugHeader :blog-slug="blogSlug" />
<UDivider class="my-3" />
<section
v-if="ast"
class="prose prose-neutral dark:prose-invert prose-sm md:prose-base prose-h1:mb-5 prose-h2:my-4 prose-pre:text-sm prose-pre:m-0 prose-li:my-1 max-w-none font-sans tracking-tight"
>
<div v-if="ast && status == 'success'">
<MDCRenderer :body="ast.body" :data="ast.data" />
<MDCRenderer :body="ast.body" :data="ast.data" tag="article" />
</div>
<div v-else-if="status == 'pending' && !ast">
<div v-else-if="status == 'pending'">
<LazyUAlert class="not-prose" title="Loading" color="primary" description="กำลังโหลดเนื้อหา กรุณารอสักครู่" variant="subtle" />
</div>
</section>
Expand All @@ -29,7 +28,6 @@
import type { RouteLocationNormalized } from 'vue-router'
import type { StrapiBlogSlug } from '~/types/StrapiBlogSlug'
const { findOne } = useStrapi()
const route: RouteLocationNormalized = useRoute()
const nuxt = useNuxtApp()
Expand All @@ -49,20 +47,20 @@ const { data } = await useAsyncData(
}
}).then((data) => data.data.attributes),
{
default(){
default() {
return blogSlug.value
},
watch: false,
deep: false,
getCachedData: (key) => {
if (nuxt.isHydrating && nuxt.payload.data[key]) {
return nuxt.payload.data[key]
}
if (nuxt.static.data[key]) {
return nuxt.static.data[key]
if (nuxt.isHydrating && nuxt.payload.data[key]) {
return nuxt.payload.data[key]
}
if (nuxt.static.data[key]) {
return nuxt.static.data[key]
}
return null
}
return null
},
}
)
Expand All @@ -80,21 +78,18 @@ definePageMeta({
middleware: ['check-blog-post']
})
const { data: ast } = useNuxtData('markdown')
const { status } = await useAsyncData('markdown', () => parseMarkdown(blogSlug.value?.content as string), {
getCachedData: (key) => {
if (nuxt.isHydrating && nuxt.payload.data[key]) {
return nuxt.payload.data[key]
}
if (nuxt.static.data[key]) {
return nuxt.static.data[key]
}
return null
const { status } = await useFetch('/api/mdc-transform', {
method: 'POST',
key: 'markdown',
body: {
content: blogSlug.value?.content
},
default(){
cache: 'force-cache',
lazy: true,
default() {
return ast.value
},
watch: false,
deep: false,
lazy: true
dedupe: 'cancel'
})
</script>

1 comment on commit ae71c01

@vercel
Copy link

@vercel vercel bot commented on ae71c01 Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.