first commit

This commit is contained in:
kbe
2025-08-18 15:31:01 +02:00
commit 316e12b98a
10 changed files with 788 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
const fs = require('fs');
const path = require('path');
const DATA_DIR = path.join(__dirname, '..', 'data', 'wordpress');
const CONTENT_DIR = path.join(__dirname, '..', 'content', 'posts');
function generateContent() {
const posts = JSON.parse(fs.readFileSync(path.join(DATA_DIR, 'posts.json'), 'utf8'));
// Ensure content directory exists
if (!fs.existsSync(CONTENT_DIR)) {
fs.mkdirSync(CONTENT_DIR, { recursive: true });
}
posts.forEach(post => {
const slug = post.slug;
const date = new Date(post.date);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const contentDir = path.join(CONTENT_DIR, `${year}-${month}-${slug}`);
if (!fs.existsSync(contentDir)) {
fs.mkdirSync(contentDir, { recursive: true });
}
const frontmatter = {
title: post.title.rendered,
date: post.date,
draft: post.status !== 'publish',
slug: slug,
wordpress_id: post.id,
excerpt: post.excerpt.rendered.replace(/<[^>]*>/g, ''),
featured_image: post._embedded?.['wp:featuredmedia']?.[0]?.source_url || '',
author: {
id: post.author,
name: post._embedded?.author?.[0]?.name || 'Unknown'
},
categories: post._embedded?.['wp:term']?.[0]?.map(cat => ({
id: cat.id,
name: cat.name,
slug: cat.slug
})) || [],
tags: post._embedded?.['wp:term']?.[1]?.map(tag => ({
id: tag.id,
name: tag.name,
slug: tag.slug
})) || []
};
const content = `---
${Object.entries(frontmatter)
.map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
.join('\n')}
---
${post.content.rendered}`;
fs.writeFileSync(path.join(contentDir, 'index.md'), content);
});
console.log(`✅ Generated ${posts.length} content files`);
}
generateContent();