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