this repo has no description

Use content with proper `$type` union

TODO for textContent in the future

Also formatting

seth.computer f74aff87 73ea9b20

verified
+31 -9
+31 -9
scripts/import-content.ts
··· 36 36 /** 37 37 * Parse YAML-like frontmatter from markdown content 38 38 */ 39 - function parseFrontmatter(content: string): { frontmatter: Frontmatter; body: string } { 40 - const frontmatterMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/); 39 + function parseFrontmatter(content: string): { 40 + frontmatter: Frontmatter; 41 + body: string; 42 + } { 43 + const frontmatterMatch = content.match( 44 + /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/, 45 + ); 41 46 42 47 if (!frontmatterMatch) { 43 48 return { frontmatter: {}, body: content }; ··· 59 64 60 65 // Array item 61 66 if (trimmed.startsWith("- ") && currentKey) { 62 - const value = trimmed.slice(2).trim().replace(/^["']|["']$/g, ""); 67 + const value = trimmed 68 + .slice(2) 69 + .trim() 70 + .replace(/^["']|["']$/g, ""); 63 71 if (currentArray) { 64 72 currentArray.push(value); 65 73 } ··· 158 166 // Remove date prefix (YYYY-MM-DD_) from filename 159 167 const parts = withoutExt.split("/"); 160 168 const filename = parts[parts.length - 1]; 161 - const filenameWithoutDate = filename?.replace(/^\d{4}-\d{2}-\d{2}_/, "") || filename; 169 + const filenameWithoutDate = 170 + filename?.replace(/^\d{4}-\d{2}-\d{2}_/, "") || filename; 162 171 parts[parts.length - 1] = filenameWithoutDate; 163 172 return `/${parts.join("/")}`; 164 173 } ··· 166 175 /** 167 176 * Recursively find all content files 168 177 */ 169 - async function findContentFiles(dir: string, baseDir: string = dir): Promise<string[]> { 178 + async function findContentFiles( 179 + dir: string, 180 + baseDir: string = dir, 181 + ): Promise<string[]> { 170 182 const files: string[] = []; 171 183 const entries = await readdir(dir, { withFileTypes: true }); 172 184 ··· 186 198 /** 187 199 * Parse a content file into a document 188 200 */ 189 - async function parseContentFile(filePath: string, baseDir: string): Promise<ParsedDocument> { 201 + async function parseContentFile( 202 + filePath: string, 203 + baseDir: string, 204 + ): Promise<ParsedDocument> { 190 205 const content = await readFile(filePath, "utf-8"); 191 206 const relativePath = relative(baseDir, filePath); 192 207 const { frontmatter, body } = parseFrontmatter(content); ··· 215 230 const record: Record<string, unknown> = { 216 231 $type: DOCUMENT_COLLECTION, 217 232 site: publicationUri, 218 - title: doc.frontmatter.title || basename(doc.relativePath, extname(doc.relativePath)), 233 + title: 234 + doc.frontmatter.title || 235 + basename(doc.relativePath, extname(doc.relativePath)), 219 236 path, 220 - textContent: doc.content, 237 + // TODO: add textContent with markdown or any other formatting stripped 238 + content: { 239 + $type: "markdown", 240 + markdown: doc.content, 241 + }, 221 242 createdAt: new Date().toISOString(), 222 243 }; 223 244 ··· 323 344 console.log(` Title: ${record.title}`); 324 345 console.log(` Path: ${record.path}`); 325 346 console.log(` Rkey: ${rkey}`); 326 - if (record.tags) console.log(` Tags: ${(record.tags as string[]).join(", ")}`); 347 + if (record.tags) 348 + console.log(` Tags: ${(record.tags as string[]).join(", ")}`); 327 349 if (record.publishedAt) console.log(` Published: ${record.publishedAt}`); 328 350 329 351 if (dryRun) {