1- import { component$ , Resource } from "@builder.io/qwik" ;
1+ import { component$ } from "@builder.io/qwik" ;
22import { routeLoader$ } from "@builder.io/qwik-city" ;
33
44import type { DocumentHead , StaticGenerateHandler } from "@builder.io/qwik-city" ;
@@ -8,68 +8,63 @@ import md from "markdown-it";
88
99import { fetchPosts , findPostBySlug } from "~/utils/posts" ;
1010
11- export const useGetPostBySlug = routeLoader$ ( async ( { params, status } ) : Promise < Post > => {
11+ export const useGetPostBySlug = routeLoader$ ( async ( { params, status } ) => {
1212 const post = await findPostBySlug ( params . slug ) ;
1313
1414 if ( ! post ) {
15- status ( 404 ) ;
15+ return status ( 404 ) ;
1616 }
1717
1818 return post as Post ;
1919} ) ;
2020
2121export default component$ ( ( ) => {
22- const data = useGetPostBySlug ( ) ;
22+ const signal = useGetPostBySlug ( ) ;
23+
24+ const post = signal . value as Post ;
2325
2426 return (
25- < Resource
26- value = { data }
27- onPending = { ( ) => < div > Loading...</ div > }
28- onRejected = { ( ) => < div > Error</ div > }
29- onResolved = { ( post : Post ) => (
30- < section class = "mx-auto py-8 sm:py-16 lg:py-20" >
31- < article >
32- < header class = { post ?. image ? "text-center" : "" } >
33- < p class = "mx-auto max-w-3xl px-4 sm:px-6" >
34- < time dateTime = { String ( post . publishDate . getTime ( ) ) } >
35- { post . publishDate . toLocaleDateString ( "en-us" , {
36- year : "numeric" ,
37- month : "short" ,
38- day : "numeric" ,
39- timeZone : "UTC" ,
40- } ) }
41- </ time >
42- { /* ~{" "} {Math.ceil(post.readingTime)} min read */ }
43- </ p >
44- < h1 class = "leading-tighter font-heading mx-auto mb-8 max-w-3xl px-4 text-4xl font-bold tracking-tighter sm:px-6 md:text-5xl" >
45- { post . title }
46- </ h1 >
47- { post . image ? (
48- < img
49- src = { post . image }
50- class = "mx-auto mt-4 mb-6 max-w-full bg-gray-400 dark:bg-slate-700 sm:rounded-md lg:max-w-6xl"
51- sizes = "(max-width: 900px) 400px, 900px"
52- alt = { post . excerpt }
53- loading = "eager"
54- width = { 900 }
55- height = { 480 }
56- />
57- ) : (
58- < div class = "mx-auto max-w-3xl px-4 sm:px-6" >
59- < div class = "border-t dark:border-slate-700" />
60- </ div >
61- ) }
62- </ header >
63- < div
64- class = "prose-md prose-headings:font-heading prose-headings:leading-tighter container prose prose-lg mx-auto mt-8 max-w-3xl px-6 prose-headings:font-bold prose-headings:tracking-tighter prose-a:text-primary-600 prose-img:rounded-md prose-img:shadow-lg dark:prose-invert dark:prose-headings:text-slate-300 dark:prose-a:text-primary-400 sm:px-6 lg:prose-xl"
65- dangerouslySetInnerHTML = { md ( {
66- html : true ,
67- } ) . render ( post . content ) }
27+ < section class = "mx-auto py-8 sm:py-16 lg:py-20" >
28+ < article >
29+ < header class = { post ?. image ? "text-center" : "" } >
30+ < p class = "mx-auto max-w-3xl px-4 sm:px-6" >
31+ < time dateTime = { String ( post . publishDate . getTime ( ) ) } >
32+ { post . publishDate . toLocaleDateString ( "en-us" , {
33+ year : "numeric" ,
34+ month : "short" ,
35+ day : "numeric" ,
36+ timeZone : "UTC" ,
37+ } ) }
38+ </ time >
39+ { /* ~{" "} {Math.ceil(post.readingTime)} min read */ }
40+ </ p >
41+ < h1 class = "leading-tighter font-heading mx-auto mb-8 max-w-3xl px-4 text-4xl font-bold tracking-tighter sm:px-6 md:text-5xl" >
42+ { post . title }
43+ </ h1 >
44+ { post . image ? (
45+ < img
46+ src = { post . image }
47+ class = "mx-auto mt-4 mb-6 max-w-full bg-gray-400 dark:bg-slate-700 sm:rounded-md lg:max-w-6xl"
48+ sizes = "(max-width: 900px) 400px, 900px"
49+ alt = { post . excerpt }
50+ loading = "eager"
51+ width = { 900 }
52+ height = { 480 }
6853 />
69- </ article >
70- </ section >
71- ) }
72- />
54+ ) : (
55+ < div class = "mx-auto max-w-3xl px-4 sm:px-6" >
56+ < div class = "border-t dark:border-slate-700" />
57+ </ div >
58+ ) }
59+ </ header >
60+ < div
61+ class = "prose-md prose-headings:font-heading prose-headings:leading-tighter container prose prose-lg mx-auto mt-8 max-w-3xl px-6 prose-headings:font-bold prose-headings:tracking-tighter prose-a:text-primary-600 prose-img:rounded-md prose-img:shadow-lg dark:prose-invert dark:prose-headings:text-slate-300 dark:prose-a:text-primary-400 sm:px-6 lg:prose-xl"
62+ dangerouslySetInnerHTML = { md ( {
63+ html : true ,
64+ } ) . render ( post . content ) }
65+ />
66+ </ article >
67+ </ section >
7368 ) ;
7469} ) ;
7570
@@ -82,7 +77,7 @@ export const onStaticGenerate: StaticGenerateHandler = async () => {
8277} ;
8378
8479export const head : DocumentHead = ( { resolveValue } ) => {
85- const post = resolveValue ( useGetPostBySlug ) ;
80+ const post = resolveValue ( useGetPostBySlug ) as Post ;
8681
8782 return {
8883 title : `${ post . title } — Qwind` ,
0 commit comments