1
1
---
2
- import type { BlogPost } from " ~/content/config.ts " ;
2
+ import type { BlogPost } from " ~/content.config " ;
3
3
import { formatPostDate , calcReadingTime , slugifyPostDate } from " ~/lib/utils" ;
4
-
4
+ import { marked } from " marked" ;
5
+ import readingTime from " reading-time" ;
6
+ import { Icon } from " astro-icon/components" ;
5
7
interface Props {
6
8
post: BlogPost ;
7
9
wordCount: number ;
8
10
}
9
11
const { post, wordCount } = Astro .props as Props ;
10
12
11
- import { marked } from " marked" ;
12
-
13
- const body = ` ${post .body
14
- .split (" " )
15
- .slice (0 , wordCount + 1 )
16
- .join (" " )}... ` ;
17
- const postBody = marked .parse (body );
13
+ const body = post ?.body ?.split (" " ).slice (0 , wordCount ).join (" " ) || " " ;
14
+ const content = marked (body );
18
15
---
19
16
20
17
<article class =" py-3.5 grid md:grid-cols-[18rem_auto]" >
@@ -24,13 +21,20 @@ const postBody = marked.parse(body);
24
21
</span >
25
22
<time
26
23
datetime ={ post .data .pubDate .toISOString ()}
27
- class =" font-semibold text-sm text-gray-700 dark:text-gray-400"
24
+ class =" font-semibold text-sm text-branding- gray-700 dark:text-gray-400"
28
25
>{ formatPostDate (post .data .pubDate )} </time
29
26
>
30
- <span
31
- class =" block mt-1 text-branding-gray-600 dark:text-branding-gray-400 text-sm font-semibold" >
32
- { calcReadingTime (post .body )}
33
- </span >
27
+ {
28
+ post .body && (
29
+ <div class = " block mt-1 text-branding-gray-600 dark:text-branding-gray-400 text-sm font-semibold ml-1" >
30
+ <div class = " inline-flex items-center justify-between" >
31
+ <Icon name = " mdi:clock" class = " inline" />
32
+ <span class = " ml-1" >{ readingTime (post .body ).text } </span >
33
+ </div >
34
+ </div >
35
+ )
36
+ }
37
+
34
38
{
35
39
post .data .series && (
36
40
<div class = " text-gray-700 dark:text-gray-400 text-sm mt-1 break-words" >
@@ -46,10 +50,10 @@ const postBody = marked.parse(body);
46
50
</h2 >
47
51
<div
48
52
class =" prose prose-neutral dark:prose-invert max-w-[80ch] prose-branding-blue"
49
- set:html ={ postBody }
53
+ set:html ={ content }
50
54
/>
51
55
<a
52
- href ={ ` /blog/${slugifyPostDate (post .data .pubDate )}/${post .slug } ` }
56
+ href ={ ` /blog/${slugifyPostDate (post .data .pubDate )}/${post .id } ` }
53
57
class =" block rounded-sm text-sm bg-branding-navy-600 w-fit text-white h-fit px-2 py-1 mt-1 dark:hover:bg-branding-navy-500 duration-100 transition-colors hover:bg-branding-navy-700"
54
58
>Read More</a
55
59
>
0 commit comments