Files
ankn b46de6dc7d
Deploy CV Site (andreknie.de) / deploy (push) Canceled after 0s
ci: migrate GitHub actions to Gitea actions
2026-07-22 15:42:06 +02:00

49 lines
1.8 KiB
JavaScript

import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
const CONTENT_DIR = path.join(process.cwd(), 'content', 'kniepunkt')
const TITLES_FILE = path.join(process.cwd(), '..', '..', '..', '..', '..', '.gemini', 'antigravity', 'brain', '12f7ab79-1833-4303-aace-1f9957dc5f67', 'kniepunkt_titles.md')
const rawTitles = fs.readFileSync(TITLES_FILE, 'utf8')
const yamlBlockMatch = rawTitles.match(/```yaml\n([\s\S]*?)```/)
if (!yamlBlockMatch) {
console.error("Could not find yaml block")
process.exit(1)
}
// Very simple parse since it's just `001: 'Title'`
const titleMap = {}
yamlBlockMatch[1].split('\n').forEach(line => {
const match = line.match(/^(\d{3}):\s*'(.*)'$/)
if (match) {
titleMap[match[1]] = match[2]
}
})
const mdFiles = fs.readdirSync(CONTENT_DIR).filter(f => f.endsWith('.md'))
mdFiles.forEach(file => {
const numMatch = file.match(/^(\d{3})-/)
if (!numMatch) return
const numStr = numMatch[1]
if (titleMap[numStr]) {
const p = path.join(CONTENT_DIR, file)
let data = matter(fs.readFileSync(p, 'utf8'))
// Set the new title! (Prepend the number to match the user's style preference, wait, they stripped it in the file. Let's prepend it so it matches standard!)
// Wait, the user provided them without the prefix in the list (e.g. 001: 'Die biblische KI'). So I should set title to: `001: Die biblische KI`.
const newTitle = `${numStr}: ${titleMap[numStr]}`
data.data.title = newTitle
// If it's 011, make sure it has the image because it was missed due to duplicate files
if (numStr === '011') {
data.data.image = `/images/kniepunkt/011-cover.png`
}
fs.writeFileSync(p, matter.stringify(data.content, data.data))
console.log(`Updated ${numStr} -> ${newTitle}`)
}
})