fix: Accent in post
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const he = require('he');
|
||||
|
||||
const DATA_DIR = path.join(__dirname, '..', 'data', 'wordpress');
|
||||
const CONTENT_DIR = path.join(__dirname, '..', 'content');
|
||||
@@ -30,12 +31,12 @@ function generateContent() {
|
||||
}
|
||||
|
||||
const frontmatter = {
|
||||
title: post.title.rendered,
|
||||
title: he.decode(post.title.rendered),
|
||||
date: post.date,
|
||||
draft: post.status !== 'publish',
|
||||
slug: slug,
|
||||
wordpress_id: post.id,
|
||||
excerpt: post.excerpt.rendered.replace(/<[^>]*>/g, ''),
|
||||
excerpt: he.decode(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é'),
|
||||
@@ -43,13 +44,18 @@ function generateContent() {
|
||||
section: categorySlug
|
||||
};
|
||||
|
||||
// Decode HTML entities in the content and clean up HTML tags
|
||||
let contentHtml = he.decode(post.content.rendered);
|
||||
contentHtml = contentHtml
|
||||
.replace(/<p>\s*<\/p>/g, '') // Remove empty paragraphs
|
||||
.replace(/<\/p>\s*<p>/g, '\n\n') // Replace paragraph breaks with newlines
|
||||
|
||||
const content = `---
|
||||
${Object.entries(frontmatter)
|
||||
.map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
|
||||
.join('\n')}
|
||||
---
|
||||
|
||||
${post.content.rendered}`;
|
||||
${contentHtml.trim()}`;
|
||||
|
||||
fs.writeFileSync(path.join(contentDir, 'index.md'), content);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user