@@ -13,8 +13,8 @@ function parseTsv(filePath) {
1313 const content = fs . readFileSync ( filePath , 'utf8' ) ;
1414 const lines = content . trim ( ) . split ( '\n' ) ;
1515 if ( lines . length < 2 ) {
16- console . error ( `No data found in TSV file: ${ filePath } ` ) ;
17- process . exit ( 1 ) ;
16+ console . warn ( `No data found in TSV file: ${ filePath } ` ) ;
17+ return [ ] ;
1818 }
1919 const headers = lines [ 0 ] . split ( '\t' ) . map ( h => h . trim ( ) ) ;
2020 const data = lines . slice ( 1 ) . map ( line => {
@@ -69,7 +69,7 @@ function preHome(allRecords) {
6969
7070 allRecords . forEach ( item => {
7171 if ( item . Id === 'BannerImage' ) {
72- const filename = path . join ( "/images/banner " , item . Filename )
72+ const filename = path . join ( "/images/photos " , item . Filename )
7373 BannerImages . push ( filename ) ;
7474 imageArchive . push ( { link : String ( item . Url ) . trim ( ) , out : filename } ) ;
7575 } else {
@@ -170,6 +170,18 @@ function preVideos(allRecords) {
170170 return allRecords ;
171171}
172172
173+ function prePhotos ( allRecords ) {
174+ allRecords . forEach ( item => {
175+ if ( ! item . Image ) return ;
176+ // Set Image path
177+ item . Image = path . join ( "/images/photos" , item . Filename ) ;
178+ // Collect image archive entry
179+ imageArchive . push ( { link : String ( item . Url ) . trim ( ) , out : item . Image } ) ;
180+ } ) ;
181+
182+ return allRecords ;
183+ }
184+
173185function processHome ( ) {
174186 const tsvPath = path . resolve ( __dirname , '../home.tsv' ) ;
175187 const outPath = path . resolve ( __dirname , '../src/data/home.json' ) ;
@@ -218,7 +230,6 @@ function processResearch() {
218230 console . log ( `Deleted TSV file: ${ tsvPath } ` ) ;
219231}
220232
221-
222233function processVideos ( ) {
223234 const tsvPath = path . resolve ( __dirname , '../videos.tsv' ) ;
224235 const outPath = path . resolve ( __dirname , '../src/data/videos.json' ) ;
@@ -266,19 +277,41 @@ function processNews() {
266277 console . log ( `Deleted TSV file: ${ tsvPath } ` ) ;
267278}
268279
280+ function processPhotos ( ) {
281+ const tsvPath = path . resolve ( __dirname , '../photos.tsv' ) ;
282+ const outPath = path . resolve ( __dirname , '../src/data/photos.json' ) ;
283+ const url = process . env . PHOTOS_SHEET ;
284+ if ( ! url ) {
285+ console . error ( 'Environment variable PHOTOS_SHEET not set' ) ;
286+ process . exit ( 1 ) ;
287+ }
288+ execSync ( `curl -L "${ url } " -o "${ tsvPath } "` , { stdio : 'inherit' } ) ;
289+ const allRecords = parseTsv ( tsvPath ) ;
290+ const data = prePhotos ( allRecords ) ;
291+ writeJson ( outPath , data ) ;
292+ fs . unlinkSync ( tsvPath ) ;
293+ console . log ( `Deleted TSV file: ${ tsvPath } ` ) ;
294+ }
295+
269296function main ( ) {
270297 processHome ( ) ;
271298 processPeople ( ) ;
272299 processResearch ( ) ;
273300 processVideos ( ) ;
274301 processPublications ( ) ;
275302 processNews ( ) ;
303+ processPhotos ( ) ;
276304
277-
278- // Write aggregated image archive (if any)
279- if ( imageArchive . length > 0 ) {
280- const archivePath = path . resolve ( __dirname , 'image-archive.json' ) ;
281- writeJson ( archivePath , imageArchive ) ;
305+ const archivePath = path . resolve ( __dirname , 'image-archive.json' ) ;
306+ // Remove duplicate entries from imageArchive based on 'link' and 'out'
307+ const uniqueArchive = Array . from (
308+ new Map ( imageArchive . map ( item => [ `${ item . link } |${ item . out } ` , item ] ) ) . values ( )
309+ ) ;
310+
311+
312+ // Write aggregated image archive
313+ if ( uniqueArchive . length > 0 ) {
314+ writeJson ( archivePath , uniqueArchive ) ;
282315 } else {
283316 console . log ( 'No image archive entries found.' ) ;
284317 }
0 commit comments