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