|
1 | 1 | import Anthropic from '@anthropic-ai/sdk' |
2 | | -import { globby } from 'globby' |
3 | 2 | import matter from 'gray-matter' |
4 | | -import { readFile, writeFile } from 'node:fs/promises' |
| 3 | +import { writeFile } from 'node:fs/promises' |
5 | 4 | import { smartypantsu } from 'smartypants' |
6 | 5 |
|
| 6 | +import { getArticles } from '../11ty/get-articles.ts' |
7 | 7 | import { |
8 | 8 | computeHash, |
9 | 9 | computeTeaserHash, |
@@ -151,21 +151,14 @@ async function main() { |
151 | 151 | const revisions = await loadRevisions() |
152 | 152 | const anthropic = process.env.ANTHROPIC_API_KEY ? new Anthropic() : null |
153 | 153 |
|
154 | | - const files = await globby('www/**/*.md') |
| 154 | + const articles = await getArticles() |
155 | 155 | let generatedCount = 0 |
156 | 156 | let teaserHashChanged = false |
157 | 157 |
|
158 | | - for (const filePath of files) { |
159 | | - const fileContent = await readFile(filePath, 'utf-8') |
160 | | - const parsed = matter(fileContent) |
161 | | - |
162 | | - const tags: string[] = parsed.data.tags ?? [] |
163 | | - if (!tags.includes('article')) continue |
164 | | - |
165 | | - const title = parsed.data.title as string |
166 | | - const subhead = parsed.data.subhead as string | undefined |
167 | | - const teaser = parsed.data.teaser as string | undefined |
168 | | - const content = parsed.content |
| 158 | + for (const { filePath, data, content, rawInput } of articles) { |
| 159 | + const title = data.title as string |
| 160 | + const subhead = data.subhead as string | undefined |
| 161 | + const teaser = data.teaser as string | undefined |
169 | 162 |
|
170 | 163 | const hash = computeHash(title, subhead, content) |
171 | 164 |
|
@@ -204,7 +197,7 @@ async function main() { |
204 | 197 | console.log(`[${decision.action}] ${filePath}: ${decision.reason}`) |
205 | 198 |
|
206 | 199 | const newTeaser = await generateTeaser(anthropic, title, content) |
207 | | - const updatedContent = insertTeaserIntoFrontmatter(fileContent, newTeaser) |
| 200 | + const updatedContent = insertTeaserIntoFrontmatter(rawInput, newTeaser) |
208 | 201 | await writeFile(filePath, updatedContent) |
209 | 202 |
|
210 | 203 | revisions.entries[filePath] ??= { revisions: [] } |
|
0 commit comments