11import { createFileRoute , Link , notFound } from '@tanstack/react-router'
2- import { extractFrontMatter , fetchRepoFile } from '~/utils/documents.server'
3- import removeMarkdown from 'remove-markdown'
42import { seo } from '~/utils/seo'
53import { Doc } from '~/components/Doc'
64import { PostNotFound } from './blog'
@@ -11,6 +9,7 @@ import { z } from 'zod'
119import { FaArrowLeft } from 'react-icons/fa'
1210import { DocContainer } from '~/components/DocContainer'
1311import { setHeaders } from 'vinxi/http'
12+ import { allPosts } from 'content-collections'
1413
1514const 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