File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,11 +24,26 @@ try {
2424 }));
2525
2626 if (response .Contents ) {
27- photos = response .Contents
27+ const filteredPhotos = response .Contents
2828 .filter ((obj : any ) => obj .Key ?.match (/ \. (jpg| jpeg| png| gif| webp)$ / i ))
29- .filter ((obj : any ) => ! obj .Key ?.startsWith (" preview_" ))
30- .map ((obj : any ) => obj .Key ! )
31- .sort ();
29+ .filter ((obj : any ) => ! obj .Key ?.startsWith (" preview_" ));
30+
31+ const sortedPhotos = filteredPhotos .sort ((a : any , b : any ) => {
32+ if (a .Metadata ?.time && b .Metadata ?.time ) {
33+ const timeA = new Date (parseInt (a .Metadata .time ) * 1000 );
34+ const timeB = new Date (parseInt (b .Metadata .time ) * 1000 );
35+ return timeB .getTime () - timeA .getTime ();
36+ }
37+ return b .Key ! .localeCompare (a .Key ! );
38+ });
39+
40+ console .table (sortedPhotos .map ((obj : any ) => ({
41+ filename: obj .Key ,
42+ timestamp: obj .Metadata ?.time || " NO TIME METADATA" ,
43+ date: obj .Metadata ?.time ? new Date (parseInt (obj .Metadata .time ) * 1000 ).toLocaleString () : " NO TIME METADATA"
44+ })));
45+
46+ photos = sortedPhotos .map ((obj : any ) => obj .Key ! );
3247 }
3348} catch (err ) {
3449 error = " Failed to load photos!" ;
Original file line number Diff line number Diff line change 4949 error = " Failed to load photo!" ;
5050}
5151---
52- <Page title =" photos" path ={ " ~/photos/" + photoKey } >
52+ <Page title =" {photoKey}" path ={ " ~/photos/" + photoKey } >
53+ <Fragment slot =" metadata" >
54+ <meta property =" og:image" content ={ photoUrl } >
55+ </Fragment >
56+
5357 { error ? (
5458 <span class = " error" >{ error } </span >
5559 ) : photoUrl ? (
You can’t perform that action at this time.
0 commit comments