@@ -2,7 +2,7 @@ import Image from "next/image";
22import Link from "next/link" ;
33
44interface ProgramAttribute {
5- image : {
5+ image ? : {
66 source_url : string ;
77 width : number ;
88 height : number ;
@@ -11,14 +11,20 @@ interface ProgramAttribute {
1111 title : string ;
1212 excerpt : string ;
1313 slug : string ;
14- authorName : string ;
15- authorImage : string ;
14+ authorName ? : string ;
15+ authorImage ? : string ;
1616 date : string ;
1717}
1818export default function SmallNewsCard ( props : ProgramAttribute ) {
1919 const { image, alt_image, title, slug, authorName, authorImage, date } =
2020 props ;
2121
22+ const fallbackImageSrc = "/shareable-card-preview.jpg" ;
23+ const fallbackAvatarSrc = "/plain-logo-blue.png" ;
24+ const imageSrc = image ?. source_url || fallbackImageSrc ;
25+ const avatarSrc = authorImage || fallbackAvatarSrc ;
26+ const safeAuthorName = authorName ?? "" ;
27+
2228 function formatDate ( date : string ) : string {
2329 const dateString = new Date ( date ) ;
2430
@@ -37,21 +43,21 @@ export default function SmallNewsCard(props: ProgramAttribute) {
3743 >
3844 < Image
3945 className = "rounded-xl w-full"
40- src = { image . source_url }
41- alt = { alt_image }
42- width = { image . width }
43- height = { image . height }
46+ src = { imageSrc }
47+ alt = { alt_image || title }
48+ width = { image ? .width ?? 400 }
49+ height = { image ? .height ?? 300 }
4450 />
4551 < div className = "flex items-center mt-2" >
4652 < Image
4753 className = "rounded-full w-6 h-6 mr-2"
48- src = { authorImage }
49- alt = { authorName }
54+ src = { avatarSrc }
55+ alt = { safeAuthorName || "Author" }
5056 width = { 24 }
5157 height = { 24 }
5258 />
5359 < span className = "text-sm text-gray-700" >
54- { authorName . split ( " " ) . filter ( Boolean ) . slice ( 0 , 2 ) . join ( " " ) }
60+ { safeAuthorName . split ( " " ) . filter ( Boolean ) . slice ( 0 , 2 ) . join ( " " ) }
5561 </ span >
5662 < span className = "text-sm text-gray-700 mx-2" > |</ span >
5763 < span className = "text-sm text-gray-700" > { formatDate ( date ) } </ span >
0 commit comments