chore: Merge branch 'chore/update-posts'
4adbdfe5
3 file(s) · +19 −16
| 6 | 6 | ||
| 7 | 7 | interface Post { |
|
| 8 | 8 | short_id: string; |
|
| 9 | - | title: string; |
|
| 9 | + | title: string | null; |
|
| 10 | 10 | slug: string; |
|
| 11 | 11 | published_date: string | null; |
|
| 12 | 12 | meta_description: string | null; |
|
| 69 | 69 | ||
| 70 | 70 | return ( |
|
| 71 | 71 | <article class="border-b pb-6 mb-6 last:border-b-0"> |
|
| 72 | - | <a |
|
| 73 | - | href={`/now/${post.slug}`} |
|
| 74 | - | class="block hover:opacity-80 transition-opacity" |
|
| 75 | - | > |
|
| 76 | - | <h3 class="text-lg font-semibold mb-3">{post.title}</h3> |
|
| 77 | - | </a> |
|
| 72 | + | {post.title && ( |
|
| 73 | + | <a |
|
| 74 | + | href={`/now/${post.slug}`} |
|
| 75 | + | class="block hover:opacity-80 transition-opacity" |
|
| 76 | + | > |
|
| 77 | + | <h3 class="text-lg font-semibold mb-3">{post.title}</h3> |
|
| 78 | + | </a> |
|
| 79 | + | )} |
|
| 78 | 80 | <div |
|
| 79 | 81 | class="prose prose-invert max-w-none mb-3" |
|
| 80 | 82 | set:html={contentHTML} |
|
| 15 | 15 | ||
| 16 | 16 | interface PostDetail { |
|
| 17 | 17 | short_id: string; |
|
| 18 | - | title: string; |
|
| 18 | + | title: string | null; |
|
| 19 | 19 | slug: string; |
|
| 20 | 20 | alias: string | null; |
|
| 21 | 21 | canonical_url: string | null; |
|
| 29 | 29 | updated_at: string; |
|
| 30 | 30 | } |
|
| 31 | 31 | ||
| 32 | - | let title = "Post"; |
|
| 32 | + | let title: string | null = "Post"; |
|
| 33 | 33 | let description = "A post"; |
|
| 34 | 34 | let contentHTML = ""; |
|
| 35 | 35 | let publishedAt = ""; |
|
| 48 | 48 | throw new Error(`HTTP ${res.status}`); |
|
| 49 | 49 | } else { |
|
| 50 | 50 | const post = (await res.json()) as PostDetail; |
|
| 51 | - | title = post.title || "Post"; |
|
| 51 | + | title = post.title; |
|
| 52 | 52 | description = |
|
| 53 | 53 | post.meta_description || |
|
| 54 | 54 | (post.content ? post.content.slice(0, 160) : description); |
|
| 66 | 66 | } |
|
| 67 | 67 | ||
| 68 | 68 | const meta = { |
|
| 69 | - | title, |
|
| 69 | + | title: title || "Post", |
|
| 70 | 70 | description, |
|
| 71 | 71 | }; |
|
| 72 | 72 | --- |
|
| 81 | 81 | </> |
|
| 82 | 82 | ) : ( |
|
| 83 | 83 | <> |
|
| 84 | - | <h1 class="text-2xl font-bold mb-2">{title}</h1> |
|
| 84 | + | {title && <h1 class="text-2xl font-bold mb-2">{title}</h1>} |
|
| 85 | 85 | <time class="text-sm text-gray-400">{publishedAt}</time> |
|
| 86 | 86 | <div class="prose prose-invert max-w-none my-4"> |
|
| 87 | 87 | <Fragment set:html={contentHTML} /> |
|
| 13 | 13 | ||
| 14 | 14 | interface Post { |
|
| 15 | 15 | short_id: string; |
|
| 16 | - | title: string; |
|
| 16 | + | title: string | null; |
|
| 17 | 17 | slug: string; |
|
| 18 | 18 | published_date: string | null; |
|
| 19 | 19 | meta_description: string | null; |
|
| 47 | 47 | }); |
|
| 48 | 48 | ||
| 49 | 49 | const items = posts.map((post) => { |
|
| 50 | - | const htmlContent = md.render(post.content || post.title); |
|
| 51 | - | const description = post.meta_description || post.title; |
|
| 50 | + | const fallback = post.content ? post.content.slice(0, 80) : post.slug; |
|
| 51 | + | const htmlContent = md.render(post.content || post.title || ""); |
|
| 52 | + | const description = post.meta_description || post.title || fallback; |
|
| 52 | 53 | ||
| 53 | 54 | return { |
|
| 54 | - | title: post.title, |
|
| 55 | + | title: post.title || fallback, |
|
| 55 | 56 | description, |
|
| 56 | 57 | pubDate: post.published_date |
|
| 57 | 58 | ? new Date(post.published_date) |
|