tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
288
fork
atom
a tool for shared writing and social publishing
288
fork
atom
overview
issues
27
pulls
pipelines
sort rss feeds properly
awarm.space
4 weeks ago
b48c51c8
5ba03576
+46
-36
1 changed file
expand all
collapse all
unified
split
app
lish
[did]
[publication]
generateFeed.ts
+46
-36
app/lish/[did]/[publication]/generateFeed.ts
···
54
});
55
56
await Promise.all(
57
-
publication.documents_in_publications.map(async (doc) => {
58
-
if (!doc.documents) return;
59
-
const record = normalizeDocumentRecord(
60
-
doc.documents?.data,
61
-
doc.documents?.uri,
62
-
);
63
-
const uri = new AtUri(doc.documents?.uri);
64
-
const rkey = uri.rkey;
65
-
if (!record) return;
0
0
0
0
0
0
0
0
0
0
66
67
-
let blocks: PubLeafletPagesLinearDocument.Block[] = [];
68
-
if (hasLeafletContent(record) && record.content.pages[0]) {
69
-
const firstPage = record.content.pages[0];
70
-
if (PubLeafletPagesLinearDocument.isMain(firstPage)) {
71
-
blocks = firstPage.blocks || [];
0
72
}
73
-
}
74
-
const stream = await renderToReadableStream(
75
-
createElement(StaticPostContent, { blocks, did: uri.host }),
76
-
);
77
-
const reader = stream.getReader();
78
-
const chunks = [];
79
80
-
let done, value;
81
-
while (!done) {
82
-
({ done, value } = await reader.read());
83
-
if (value) {
84
-
chunks.push(new TextDecoder().decode(value));
0
85
}
86
-
}
87
88
-
const docUrl = getDocumentURL(record, doc.documents.uri, pubRecord);
89
-
feed.addItem({
90
-
title: record.title,
91
-
description: record.description,
92
-
date: record.publishedAt ? new Date(record.publishedAt) : new Date(),
93
-
id: docUrl,
94
-
link: docUrl,
95
-
content: chunks.join(""),
96
-
});
97
-
}),
98
);
99
100
return feed;
···
54
});
55
56
await Promise.all(
57
+
publication.documents_in_publications
58
+
.sort((a, b) => {
59
+
const dateA = a.documents?.sort_date
60
+
? new Date(a.documents.sort_date).getTime()
61
+
: 0;
62
+
const dateB = b.documents?.sort_date
63
+
? new Date(b.documents.sort_date).getTime()
64
+
: 0;
65
+
return dateB - dateA; // Sort in descending order (newest first)
66
+
})
67
+
.map(async (doc) => {
68
+
if (!doc.documents) return;
69
+
const record = normalizeDocumentRecord(
70
+
doc.documents?.data,
71
+
doc.documents?.uri,
72
+
);
73
+
const uri = new AtUri(doc.documents?.uri);
74
+
const rkey = uri.rkey;
75
+
if (!record) return;
76
77
+
let blocks: PubLeafletPagesLinearDocument.Block[] = [];
78
+
if (hasLeafletContent(record) && record.content.pages[0]) {
79
+
const firstPage = record.content.pages[0];
80
+
if (PubLeafletPagesLinearDocument.isMain(firstPage)) {
81
+
blocks = firstPage.blocks || [];
82
+
}
83
}
84
+
const stream = await renderToReadableStream(
85
+
createElement(StaticPostContent, { blocks, did: uri.host }),
86
+
);
87
+
const reader = stream.getReader();
88
+
const chunks = [];
0
89
90
+
let done, value;
91
+
while (!done) {
92
+
({ done, value } = await reader.read());
93
+
if (value) {
94
+
chunks.push(new TextDecoder().decode(value));
95
+
}
96
}
0
97
98
+
const docUrl = getDocumentURL(record, doc.documents.uri, pubRecord);
99
+
feed.addItem({
100
+
title: record.title,
101
+
description: record.description,
102
+
date: record.publishedAt ? new Date(record.publishedAt) : new Date(),
103
+
id: docUrl,
104
+
link: docUrl,
105
+
content: chunks.join(""),
106
+
});
107
+
}),
108
);
109
110
return feed;