Display categories
This commit is contained in:
@@ -68,16 +68,67 @@ async function generateData() {
|
||||
modified: page.modified
|
||||
}));
|
||||
|
||||
// Create author-post mapping
|
||||
const authorPosts = {};
|
||||
posts.forEach(post => {
|
||||
if (post.status === 'publish') {
|
||||
const author = post._embedded?.author?.[0];
|
||||
if (author) {
|
||||
const authorSlug = author.slug;
|
||||
if (!authorPosts[authorSlug]) {
|
||||
authorPosts[authorSlug] = {
|
||||
id: author.id,
|
||||
name: author.name,
|
||||
slug: author.slug,
|
||||
description: author.description || '',
|
||||
avatar: author.avatar_urls || {},
|
||||
link: author.link,
|
||||
posts: []
|
||||
};
|
||||
}
|
||||
authorPosts[authorSlug].posts.push({
|
||||
id: post.id,
|
||||
title: post.title.rendered,
|
||||
slug: post.slug,
|
||||
date: post.date,
|
||||
excerpt: post.excerpt.rendered,
|
||||
featured_image: post._embedded?.['wp:featuredmedia']?.[0]?.source_url || '',
|
||||
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
|
||||
}))
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Save data as JSON files
|
||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'posts.json'), JSON.stringify(posts, null, 2));
|
||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'pages.json'), JSON.stringify(publishedPages, null, 2));
|
||||
// Extract category descriptions
|
||||
const categoriesWithDescriptions = categories.map(cat => ({
|
||||
id: cat.id,
|
||||
name: cat.name,
|
||||
slug: cat.slug,
|
||||
description: cat.description || '',
|
||||
count: cat.count || 0
|
||||
}));
|
||||
|
||||
// Also save to wordpress directory
|
||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'categories.json'), JSON.stringify(categories, null, 2));
|
||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'tags.json'), JSON.stringify(tags, null, 2));
|
||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'authors.json'), JSON.stringify(authors, null, 2));
|
||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'author-posts.json'), JSON.stringify(authorPosts, null, 2));
|
||||
fs.writeFileSync(path.join(OUTPUT_DIR, 'navigation.json'), JSON.stringify(navigationData, null, 2));
|
||||
|
||||
console.log(`✅ Fetched ${posts.length} posts, ${publishedPages.length} pages, ${categories.length} categories, ${tags.length} tags, ${authors.length} authors`);
|
||||
console.log(`✅ Generated navigation data with ${navigationData.length} items`);
|
||||
}
|
||||
|
||||
generateData().catch(console.error);
|
||||
generateData().catch(console.error);
|
||||
|
||||
@@ -161,22 +161,47 @@ function generateAuthorDirectories(posts) {
|
||||
fs.mkdirSync(AUTHORS_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
// Group posts by author
|
||||
// Group posts by author using proper author data
|
||||
const postsByAuthor = {};
|
||||
|
||||
posts.forEach(post => {
|
||||
const authorName = post._embedded?.author?.[0]?.name || 'Unknown';
|
||||
const authorSlug = authorName.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, '');
|
||||
|
||||
if (!postsByAuthor[authorSlug]) {
|
||||
postsByAuthor[authorSlug] = {
|
||||
name: authorName,
|
||||
slug: authorSlug,
|
||||
posts: []
|
||||
};
|
||||
const author = post._embedded?.author?.[0];
|
||||
if (author) {
|
||||
const authorSlug = author.slug;
|
||||
const authorName = author.name;
|
||||
|
||||
if (!postsByAuthor[authorSlug]) {
|
||||
postsByAuthor[authorSlug] = {
|
||||
id: author.id,
|
||||
name: authorName,
|
||||
slug: authorSlug,
|
||||
description: author.description || '',
|
||||
avatar: author.avatar_urls || {},
|
||||
link: author.link,
|
||||
posts: []
|
||||
};
|
||||
}
|
||||
|
||||
postsByAuthor[authorSlug].posts.push(post);
|
||||
} else {
|
||||
// Handle unknown author
|
||||
const unknownSlug = 'unknown';
|
||||
const unknownName = 'Unknown';
|
||||
|
||||
if (!postsByAuthor[unknownSlug]) {
|
||||
postsByAuthor[unknownSlug] = {
|
||||
id: 0,
|
||||
name: unknownName,
|
||||
slug: unknownSlug,
|
||||
description: '',
|
||||
avatar: {},
|
||||
link: '',
|
||||
posts: []
|
||||
};
|
||||
}
|
||||
|
||||
postsByAuthor[unknownSlug].posts.push(post);
|
||||
}
|
||||
|
||||
postsByAuthor[authorSlug].posts.push(post);
|
||||
});
|
||||
|
||||
// Create author directories and index pages
|
||||
@@ -187,13 +212,17 @@ function generateAuthorDirectories(posts) {
|
||||
fs.mkdirSync(authorDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Generate author index page
|
||||
// Generate author index page with proper metadata
|
||||
const frontmatter = {
|
||||
title: `Lise des articles de ${author.name}`,
|
||||
title: `Articles de ${author.name}`,
|
||||
type: 'authors',
|
||||
layout: 'list',
|
||||
author: author.name,
|
||||
author_slug: author.slug
|
||||
author_slug: author.slug,
|
||||
description: author.description,
|
||||
avatar: author.avatar,
|
||||
link: author.link,
|
||||
post_count: author.posts.length
|
||||
};
|
||||
|
||||
const content = `---
|
||||
@@ -209,4 +238,4 @@ ${Object.entries(frontmatter)
|
||||
});
|
||||
}
|
||||
|
||||
generateContent();
|
||||
generateContent();
|
||||
|
||||
Reference in New Issue
Block a user