Skip to content

Commit 302347e

Browse files
committed
feat: slug page to use content-collections
1 parent b2f1b7c commit 302347e

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

app/routes/_libraries/blog.$.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { createFileRoute, Link, notFound } from '@tanstack/react-router'
2-
import { extractFrontMatter, fetchRepoFile } from '~/utils/documents.server'
3-
import removeMarkdown from 'remove-markdown'
42
import { seo } from '~/utils/seo'
53
import { Doc } from '~/components/Doc'
64
import { PostNotFound } from './blog'
@@ -11,6 +9,7 @@ import { z } from 'zod'
119
import { FaArrowLeft } from 'react-icons/fa'
1210
import { DocContainer } from '~/components/DocContainer'
1311
import { setHeaders } from 'vinxi/http'
12+
import { allPosts } from 'content-collections'
1413

1514
const fetchBlogPost = createServerFn({ method: 'GET' })
1615
.validator(z.string().optional())
@@ -21,27 +20,24 @@ const fetchBlogPost = createServerFn({ method: 'GET' })
2120

2221
const filePath = `app/blog/${docsPath}.md`
2322

24-
const file = await fetchRepoFile('tanstack/tanstack.com', 'main', filePath)
23+
const post = allPosts.find((post) => post.slug === docsPath)
2524

26-
if (!file) {
25+
if (!post) {
2726
throw notFound()
2827
}
2928

30-
const frontMatter = extractFrontMatter(file)
31-
const description = removeMarkdown(frontMatter.excerpt ?? '')
32-
3329
setHeaders({
3430
'cache-control': 'public, max-age=0, must-revalidate',
3531
'cdn-cache-control': 'max-age=300, stale-while-revalidate=300, durable',
3632
'Netlify-Vary': 'query=payload',
3733
})
3834

3935
return {
40-
title: frontMatter.data.title,
41-
description,
42-
published: frontMatter.data.published,
43-
content: frontMatter.content,
44-
authors: (frontMatter.data.authors ?? []) as Array<string>,
36+
title: post.title,
37+
description: post.excerpt,
38+
published: post.published,
39+
content: post.content,
40+
authors: post.authors,
4541
filePath,
4642
}
4743
})

0 commit comments

Comments
 (0)