ci: migrate GitHub actions to Gitea actions
Deploy CV Site (andreknie.de) / deploy (push) Canceled after 0s
Deploy CV Site (andreknie.de) / deploy (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
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 allPosts = getFiles(POSTS_DIR)
|
||||
const allKniepunkte = getFiles(KNIEPUNKT_DIR)
|
||||
|
||||
// 1. Clean up Kniepunkt Residues in posts/
|
||||
allPosts.forEach(post => {
|
||||
const filename = path.basename(post)
|
||||
if (filename.match(/^0[1-9][0-9]/)) {
|
||||
const issueMatch = filename.match(/^0([1-9][0-9])/)
|
||||
if (issueMatch) {
|
||||
const issueNum = issueMatch[1]
|
||||
const matchingKniepunkt = allKniepunkte.find(k => path.basename(k).includes(`0${issueNum}`) || path.basename(k).includes(issueNum))
|
||||
if (matchingKniepunkt) {
|
||||
console.log(`🗑️ Deleting residue in posts/: ${filename}`)
|
||||
fs.unlinkSync(post)
|
||||
} else {
|
||||
// move to kniepunkt
|
||||
const newPath = path.join(KNIEPUNKT_DIR, filename)
|
||||
fs.renameSync(post, newPath)
|
||||
console.log(`➡️ Moved residue to kniepunkt/: ${filename}`)
|
||||
allKniepunkte.push(newPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 2. Merge intro posts in kniepunkt/
|
||||
const introPosts = allKniepunkte.filter(k => path.basename(k).match(/^202[0-9]-/))
|
||||
introPosts.forEach(intro => {
|
||||
const introData = matter(fs.readFileSync(intro, 'utf8'))
|
||||
const titleMatch = introData.data.title.match(/kniepunkt\s*0?(\d+)/i) || path.basename(intro).match(/kniepunkt-0?(\d+)/i)
|
||||
|
||||
if (titleMatch) {
|
||||
const issueNum = titleMatch[1]
|
||||
const article = allKniepunkte.find(k => k !== intro && (path.basename(k).includes(`0${issueNum}`) || path.basename(k).includes(`-${issueNum}-`)) && !path.basename(k).match(/^202[0-9]-/))
|
||||
|
||||
if (article) {
|
||||
const articleData = matter(fs.readFileSync(article, 'utf8'))
|
||||
const mergedContent = introData.content.trim() + '\n\n---\n\n' + articleData.content.trim()
|
||||
articleData.data.date = introData.data.date
|
||||
fs.writeFileSync(article, matter.stringify(mergedContent, articleData.data))
|
||||
fs.unlinkSync(intro)
|
||||
console.log(`✅ Merged Intro ${path.basename(intro)} -> ${path.basename(article)}`)
|
||||
} else {
|
||||
console.log(`⚠️ Could not find article for intro: ${path.basename(intro)} (Issue ${issueNum})`)
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user