tangled
alpha
login
or
join now
apoena.dev
/
sequoia
forked from
stevedylan.dev/sequoia
0
fork
atom
A CLI for publishing standard.site documents to ATProto
0
fork
atom
overview
issues
pulls
pipelines
refacto: build note record
Julien Calixte
1 month ago
0a2bd2cc
de35e7d5
+27
-34
1 changed file
expand all
collapse all
unified
split
packages
cli
src
extensions
remanso.ts
+27
-34
packages/cli/src/extensions/remanso.ts
···
181
181
return uriMatch[3]!
182
182
}
183
183
184
184
-
export async function createNote(
184
184
+
async function buildNoteRecord(
185
185
agent: Agent,
186
186
post: BlogPost,
187
187
-
atUri: string,
188
187
options: NoteOptions,
189
189
-
): Promise<void> {
190
190
-
const rkey = parseRkey(atUri)
188
188
+
): Promise<Record<string, unknown>> {
191
189
const publishDate = new Date(post.frontmatter.publishDate).toISOString()
192
190
const trimmedContent = post.content.trim()
193
191
const titleMatch = trimmedContent.match(/^# (.+)$/m)
···
207
205
record.images = images
208
206
}
209
207
208
208
+
if (post.frontmatter.theme) {
209
209
+
record.theme = post.frontmatter.theme
210
210
+
}
211
211
+
212
212
+
if (post.frontmatter.fontSize) {
213
213
+
record.fontSize = post.frontmatter.fontSize
214
214
+
}
215
215
+
216
216
+
if (post.frontmatter.fontFamily) {
217
217
+
record.fontFamily = post.frontmatter.fontFamily
218
218
+
}
219
219
+
220
220
+
return record
221
221
+
}
222
222
+
223
223
+
export async function createNote(
224
224
+
agent: Agent,
225
225
+
post: BlogPost,
226
226
+
atUri: string,
227
227
+
options: NoteOptions,
228
228
+
): Promise<void> {
229
229
+
const rkey = parseRkey(atUri)
230
230
+
const record = await buildNoteRecord(agent, post, options)
231
231
+
210
232
await agent.com.atproto.repo.createRecord({
211
233
repo: agent.did!,
212
234
collection: LEXICON,
···
223
245
options: NoteOptions,
224
246
): Promise<void> {
225
247
const rkey = parseRkey(atUri)
226
226
-
const publishDate = new Date(post.frontmatter.publishDate).toISOString()
227
227
-
const trimmedContent = post.content.trim()
228
228
-
const titleMatch = trimmedContent.match(/^# (.+)$/m)
229
229
-
const title = titleMatch ? titleMatch[1] : post.frontmatter.title
230
230
-
231
231
-
const { content, images } = await processNoteContent(agent, post, options)
232
232
-
233
233
-
const record: Record<string, unknown> = {
234
234
-
$type: LEXICON,
235
235
-
title,
236
236
-
content: content.slice(0, MAX_CONTENT),
237
237
-
createdAt: publishDate,
238
238
-
publishedAt: publishDate,
239
239
-
}
240
240
-
241
241
-
if (images.length > 0) {
242
242
-
record.images = images
243
243
-
}
244
244
-
245
245
-
if (post.frontmatter.theme) {
246
246
-
record.theme = post.frontmatter.theme
247
247
-
}
248
248
-
249
249
-
if (post.frontmatter.fontSize) {
250
250
-
record.fontSize = post.frontmatter.fontSize
251
251
-
}
252
252
-
253
253
-
if (post.frontmatter.fontFamily) {
254
254
-
record.fontFamily = post.frontmatter.fontFamily
255
255
-
}
248
248
+
const record = await buildNoteRecord(agent, post, options)
256
249
257
250
await agent.com.atproto.repo.putRecord({
258
251
repo: agent.did!,