@@ -17,47 +17,51 @@ export const generateMetadataBody = async ({
1717 data,
1818 acceptedKeys,
1919} : MetadataConfig ) => {
20- const filteredData = Object . entries ( data )
21- . filter ( ( [ key , value ] ) => value && acceptedKeys . includes ( key ) )
22- . map ( ( [ key , value ] ) => [ key , value ] ) ;
23-
24- const references = data ?. references
25- ? // uri should not be optional. It is just not yet supported on govtool
26- ( data . references as Array < Partial < Reference > > )
27- . filter ( ( link ) => link . uri )
28- . map ( ( link ) => ( {
29- "@type" : link [ "@type" ] ?? "Other" ,
30- label : link . label ?? "Label" ,
31- uri : link . uri ,
32- } ) )
33- : undefined ;
34-
35- const isUrl = ( url ?: unknown ) => URL_REGEX . test ( url as string ) ;
36- let image ;
37-
38- if ( isUrl ( data ?. image ) ) {
39- image = {
40- "@type" : "ImageObject" ,
41- contentUrl : data . image ,
42- sha256 : await getImageSha ( data . image as string ) ,
43- } ;
44- } else {
45- image = data ?. image
46- ? {
47- "@type" : "ImageObject" ,
48- contentUrl : data . image ,
49- }
20+ try {
21+ const filteredData = Object . entries ( data )
22+ . filter ( ( [ key , value ] ) => value && acceptedKeys . includes ( key ) )
23+ . map ( ( [ key , value ] ) => [ key , value ] ) ;
24+
25+ const references = data ?. references
26+ ? // uri should not be optional. It is just not yet supported on govtool
27+ ( data . references as Array < Partial < Reference > > )
28+ . filter ( ( link ) => link . uri )
29+ . map ( ( link ) => ( {
30+ "@type" : link [ "@type" ] ?? "Other" ,
31+ label : link . label ?? "Label" ,
32+ uri : link . uri ,
33+ } ) )
5034 : undefined ;
51- }
5235
53- const body = Object . fromEntries ( filteredData ) ;
54- if ( references ?. length ) {
55- body . references = references ;
56- }
36+ const isUrl = ( url ?: unknown ) => URL_REGEX . test ( url as string ) ;
37+ let image ;
5738
58- if ( image ) {
59- body . image = image ;
60- }
39+ if ( isUrl ( data ?. image ) ) {
40+ image = {
41+ "@type" : "ImageObject" ,
42+ contentUrl : data . image ,
43+ sha256 : await getImageSha ( data . image as string ) ,
44+ } ;
45+ } else {
46+ image = data ?. image
47+ ? {
48+ "@type" : "ImageObject" ,
49+ contentUrl : data . image ,
50+ }
51+ : undefined ;
52+ }
6153
62- return body ;
54+ const body = Object . fromEntries ( filteredData ) ;
55+ if ( references ?. length ) {
56+ body . references = references ;
57+ }
58+
59+ if ( image ) {
60+ body . image = image ;
61+ }
62+
63+ return body ;
64+ } catch ( error ) {
65+ console . error ( { error } ) ;
66+ }
6367} ;
0 commit comments