Files
Orchestrator/privat/CV/andreknie.de/scripts/fix-content.js
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

56 lines
1.9 KiB
JavaScript

import fs from 'fs'
import path from 'path'
import matter from 'gray-matter'
const CONTENT_DIR = path.join(process.cwd(), 'content')
const KNIEPUNKT_DIR = path.join(CONTENT_DIR, 'kniepunkt')
const POSTS_DIR = path.join(CONTENT_DIR, 'posts')
function getFiles(dir) {
return fs.readdirSync(dir).map(f => path.join(dir, f)).filter(f => f.endsWith('.md'))
}
const allFiles = [...getFiles(KNIEPUNKT_DIR), ...getFiles(POSTS_DIR)]
allFiles.forEach(file => {
const content = fs.readFileSync(file, 'utf-8')
const { data, content: body } = matter(content)
// Delete empty or almost empty files (like the bad PDF parses)
if (body.trim().length < 50) {
console.log(`🗑️ Deleting empty file: ${path.basename(file)}`)
fs.unlinkSync(file)
return
}
const filename = path.basename(file).toLowerCase()
const title = (data.title || '').toLowerCase()
const isKniepunkt = filename.includes('kniepunkt') || title.includes('kniepunkt')
const targetDir = isKniepunkt ? KNIEPUNKT_DIR : POSTS_DIR
const targetPath = path.join(targetDir, path.basename(file))
// Adjust date for Kniepunkte (must be Sunday)
if (isKniepunkt && data.date) {
const d = new Date(data.date)
const day = d.getDay()
if (day !== 0) {
// Shift to nearest Sunday (if Saturday, +1. If Monday, -1)
const diff = day === 6 ? 1 : (day === 1 ? -1 : (day > 3 ? 7 - day : -day))
d.setDate(d.getDate() + diff)
data.date = d.toISOString().split('T')[0]
}
}
// If it's the wrong directory or we need to update the date, rewrite it
if (file !== targetPath || isKniepunkt) {
console.log(`📦 Moving/Updating: ${path.basename(file)} -> ${isKniepunkt ? 'kniepunkt' : 'posts'}`)
const newContent = matter.stringify(body, data)
fs.writeFileSync(targetPath, newContent)
if (file !== targetPath) {
fs.unlinkSync(file)
}
}
})
console.log('✅ Cleanup complete!')