@@ -15,6 +15,8 @@ type ListingLike = {
1515 country_code ?: string | null ;
1616 area_name ?: string | null ;
1717 description ?: string | null ;
18+ accepted_items ?: string [ ] | null ;
19+ rejected_items ?: string [ ] | null ;
1820 photos ?: string [ ] | null ;
1921 coordinates ?: ListingCoordinates | null ;
2022} ;
@@ -98,6 +100,36 @@ function compactTextParts(parts: Array<string | null | undefined>) {
98100 . filter ( ( part ) : part is string => Boolean ( part ) ) ;
99101}
100102
103+ function compactTextList ( items : string [ ] | null | undefined ) {
104+ return items
105+ ?. map ( ( item ) => item . trim ( ) )
106+ . filter ( ( item ) : item is string => Boolean ( item ) ) ;
107+ }
108+
109+ function getListingItemProperties ( listing : ListingLike ) {
110+ const acceptedItems = compactTextList ( listing . accepted_items ) ?? [ ] ;
111+ const rejectedItems = compactTextList ( listing . rejected_items ) ?? [ ] ;
112+
113+ return [
114+ acceptedItems . length
115+ ? {
116+ "@type" : "PropertyValue" ,
117+ name : "Accepted food scraps" ,
118+ propertyID : "acceptedItems" ,
119+ value : acceptedItems . join ( ", " ) ,
120+ }
121+ : null ,
122+ rejectedItems . length
123+ ? {
124+ "@type" : "PropertyValue" ,
125+ name : "Items not accepted" ,
126+ propertyID : "rejectedItems" ,
127+ value : rejectedItems . join ( ", " ) ,
128+ }
129+ : null ,
130+ ] . filter ( ( item ) : item is NonNullable < typeof item > => Boolean ( item ) ) ;
131+ }
132+
101133function getListingCountryName (
102134 listing : ListingLike | null | undefined ,
103135 locale ?: string
@@ -390,6 +422,9 @@ export function generateListingJsonLd(
390422 const structuredDataImage = canIncludePublicStructuredDetails
391423 ? getListingStructuredDataImage ( listing , user )
392424 : null ;
425+ const itemProperties = canIncludePublicStructuredDetails
426+ ? getListingItemProperties ( listing )
427+ : [ ] ;
393428 const address = {
394429 "@type" : "PostalAddress" ,
395430 ...( listing . area_name ? { addressLocality : listing . area_name } : { } ) ,
@@ -412,6 +447,7 @@ export function generateListingJsonLd(
412447 }
413448 : { } ) ,
414449 ...( structuredDataImage ? { image : structuredDataImage } : { } ) ,
450+ ...( itemProperties . length ? { additionalProperty : itemProperties } : { } ) ,
415451 } ;
416452
417453 return {
0 commit comments