a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

sort posts in feed

+18 -6
+18 -6
feeds/index.ts
··· 34 34 .eq("identity", auth); 35 35 const feed = (publications || []).flatMap((pub) => { 36 36 let posts = pub.publications?.documents_in_publications || []; 37 - return posts.flatMap((p) => { 38 - if (!p.documents?.data) return []; 39 - let record = p.documents.data as PubLeafletDocument.Record; 40 - if (!record.postRef) return []; 41 - return { post: record.postRef.uri }; 42 - }); 37 + return posts 38 + .sort((a, b) => { 39 + let aRecord = a.documents?.data! as PubLeafletDocument.Record; 40 + let bRecord = b.documents?.data! as PubLeafletDocument.Record; 41 + const aDate = aRecord.publishedAt 42 + ? new Date(aRecord.publishedAt) 43 + : new Date(0); 44 + const bDate = bRecord.publishedAt 45 + ? new Date(bRecord.publishedAt) 46 + : new Date(0); 47 + return bDate.getTime() - aDate.getTime(); // Sort by most recent first 48 + }) 49 + .flatMap((p) => { 50 + if (!p.documents?.data) return []; 51 + let record = p.documents.data as PubLeafletDocument.Record; 52 + if (!record.postRef) return []; 53 + return { post: record.postRef.uri }; 54 + }); 43 55 }); 44 56 45 57 return c.json({