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 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
54
});
55
55
56
56
await Promise.all(
57
57
-
publication.documents_in_publications.map(async (doc) => {
58
58
-
if (!doc.documents) return;
59
59
-
const record = normalizeDocumentRecord(
60
60
-
doc.documents?.data,
61
61
-
doc.documents?.uri,
62
62
-
);
63
63
-
const uri = new AtUri(doc.documents?.uri);
64
64
-
const rkey = uri.rkey;
65
65
-
if (!record) return;
57
57
+
publication.documents_in_publications
58
58
+
.sort((a, b) => {
59
59
+
const dateA = a.documents?.sort_date
60
60
+
? new Date(a.documents.sort_date).getTime()
61
61
+
: 0;
62
62
+
const dateB = b.documents?.sort_date
63
63
+
? new Date(b.documents.sort_date).getTime()
64
64
+
: 0;
65
65
+
return dateB - dateA; // Sort in descending order (newest first)
66
66
+
})
67
67
+
.map(async (doc) => {
68
68
+
if (!doc.documents) return;
69
69
+
const record = normalizeDocumentRecord(
70
70
+
doc.documents?.data,
71
71
+
doc.documents?.uri,
72
72
+
);
73
73
+
const uri = new AtUri(doc.documents?.uri);
74
74
+
const rkey = uri.rkey;
75
75
+
if (!record) return;
66
76
67
67
-
let blocks: PubLeafletPagesLinearDocument.Block[] = [];
68
68
-
if (hasLeafletContent(record) && record.content.pages[0]) {
69
69
-
const firstPage = record.content.pages[0];
70
70
-
if (PubLeafletPagesLinearDocument.isMain(firstPage)) {
71
71
-
blocks = firstPage.blocks || [];
77
77
+
let blocks: PubLeafletPagesLinearDocument.Block[] = [];
78
78
+
if (hasLeafletContent(record) && record.content.pages[0]) {
79
79
+
const firstPage = record.content.pages[0];
80
80
+
if (PubLeafletPagesLinearDocument.isMain(firstPage)) {
81
81
+
blocks = firstPage.blocks || [];
82
82
+
}
72
83
}
73
73
-
}
74
74
-
const stream = await renderToReadableStream(
75
75
-
createElement(StaticPostContent, { blocks, did: uri.host }),
76
76
-
);
77
77
-
const reader = stream.getReader();
78
78
-
const chunks = [];
84
84
+
const stream = await renderToReadableStream(
85
85
+
createElement(StaticPostContent, { blocks, did: uri.host }),
86
86
+
);
87
87
+
const reader = stream.getReader();
88
88
+
const chunks = [];
79
89
80
80
-
let done, value;
81
81
-
while (!done) {
82
82
-
({ done, value } = await reader.read());
83
83
-
if (value) {
84
84
-
chunks.push(new TextDecoder().decode(value));
90
90
+
let done, value;
91
91
+
while (!done) {
92
92
+
({ done, value } = await reader.read());
93
93
+
if (value) {
94
94
+
chunks.push(new TextDecoder().decode(value));
95
95
+
}
85
96
}
86
86
-
}
87
97
88
88
-
const docUrl = getDocumentURL(record, doc.documents.uri, pubRecord);
89
89
-
feed.addItem({
90
90
-
title: record.title,
91
91
-
description: record.description,
92
92
-
date: record.publishedAt ? new Date(record.publishedAt) : new Date(),
93
93
-
id: docUrl,
94
94
-
link: docUrl,
95
95
-
content: chunks.join(""),
96
96
-
});
97
97
-
}),
98
98
+
const docUrl = getDocumentURL(record, doc.documents.uri, pubRecord);
99
99
+
feed.addItem({
100
100
+
title: record.title,
101
101
+
description: record.description,
102
102
+
date: record.publishedAt ? new Date(record.publishedAt) : new Date(),
103
103
+
id: docUrl,
104
104
+
link: docUrl,
105
105
+
content: chunks.join(""),
106
106
+
});
107
107
+
}),
98
108
);
99
109
100
110
return feed;