This repository has been archived on 2025-08-21. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
hugo-mistergeek/scripts/generate-content.js
kbe fced4930c1 refactor: update content structure and layout templates
- Updated author format in content files
- Added section field to content files
- Simplified categories format
- Removed no-category.html layout
- Updated list.html and single.html layouts
- Updated index.html layout
- Updated generate-content.js script
- Do not index content with git
2025-08-18 17:41:53 +02:00

60 lines
2.0 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const DATA_DIR = path.join(__dirname, '..', 'data', 'wordpress');
const CONTENT_DIR = path.join(__dirname, '..', 'content');
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');
// Get the primary category (first category in the list)
const primaryCategory = post._embedded?.['wp:term']?.[0]?.[0];
const categorySlug = primaryCategory ? primaryCategory.slug : 'non-classe';
const contentDir = path.join(CONTENT_DIR, categorySlug, `${year}-${month}-${slug}`);
// 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: post._embedded?.author?.[0]?.name || 'Unknown',
categories: (post._embedded?.['wp:term']?.[0] || []).map(cat => cat.name || 'Non classé'),
tags: (post._embedded?.['wp:term']?.[1] || []).map(cat => cat.name || 'Non classé'),
section: categorySlug
};
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();