tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
27
pulls
pipelines
sort posts properly
awarm.space
9 months ago
c462b0e8
42ba44d4
+22
-22
1 changed file
expand all
collapse all
unified
split
feeds
index.ts
+22
-22
feeds/index.ts
···
32
32
.from("publication_subscriptions")
33
33
.select(`publications(documents_in_publications(documents(*)))`)
34
34
.eq("identity", auth);
35
35
-
const feed = (publications || []).flatMap((pub) => {
36
36
-
let posts = pub.publications?.documents_in_publications || [];
37
37
-
return posts
38
38
-
.sort((a, b) => {
39
39
-
let aRecord = a.documents?.data! as PubLeafletDocument.Record;
40
40
-
let bRecord = b.documents?.data! as PubLeafletDocument.Record;
41
41
-
const aDate = aRecord.publishedAt
42
42
-
? new Date(aRecord.publishedAt)
43
43
-
: new Date(0);
44
44
-
const bDate = bRecord.publishedAt
45
45
-
? new Date(bRecord.publishedAt)
46
46
-
: new Date(0);
47
47
-
return bDate.getTime() - aDate.getTime(); // Sort by most recent first
48
48
-
})
49
49
-
.flatMap((p) => {
50
50
-
if (!p.documents?.data) return [];
51
51
-
let record = p.documents.data as PubLeafletDocument.Record;
52
52
-
if (!record.postRef) return [];
53
53
-
return { post: record.postRef.uri };
54
54
-
});
55
55
-
});
56
56
-
35
35
+
const feed = (publications || [])
36
36
+
.flatMap((pub) => {
37
37
+
let posts = pub.publications?.documents_in_publications || [];
38
38
+
return posts;
39
39
+
})
40
40
+
.sort((a, b) => {
41
41
+
let aRecord = a.documents?.data! as PubLeafletDocument.Record;
42
42
+
let bRecord = b.documents?.data! as PubLeafletDocument.Record;
43
43
+
const aDate = aRecord.publishedAt
44
44
+
? new Date(aRecord.publishedAt)
45
45
+
: new Date(0);
46
46
+
const bDate = bRecord.publishedAt
47
47
+
? new Date(bRecord.publishedAt)
48
48
+
: new Date(0);
49
49
+
return bDate.getTime() - aDate.getTime(); // Sort by most recent first
50
50
+
})
51
51
+
.flatMap((p) => {
52
52
+
if (!p.documents?.data) return [];
53
53
+
let record = p.documents.data as PubLeafletDocument.Record;
54
54
+
if (!record.postRef) return [];
55
55
+
return { post: record.postRef.uri };
56
56
+
});
57
57
return c.json({
58
58
feed,
59
59
});