Author page ok
This commit is contained in:
@@ -145,8 +145,68 @@ ${contentHtml.trim()}`;
|
||||
|
||||
const publishedPosts = posts.filter(post => post.status === 'publish');
|
||||
const publishedPages = pages.filter(page => page.status === 'publish');
|
||||
|
||||
// Generate author directories and index pages
|
||||
generateAuthorDirectories(publishedPosts);
|
||||
|
||||
console.log(`✅ Generated ${publishedPosts.length} content files`);
|
||||
console.log(`✅ Generated ${publishedPages.length} page files`);
|
||||
}
|
||||
|
||||
function generateAuthorDirectories(posts) {
|
||||
const AUTHORS_DIR = path.join(CONTENT_DIR, 'author');
|
||||
|
||||
// Ensure authors directory exists
|
||||
if (!fs.existsSync(AUTHORS_DIR)) {
|
||||
fs.mkdirSync(AUTHORS_DIR, { recursive: true });
|
||||
}
|
||||
|
||||
// Group posts by author
|
||||
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: []
|
||||
};
|
||||
}
|
||||
|
||||
postsByAuthor[authorSlug].posts.push(post);
|
||||
});
|
||||
|
||||
// Create author directories and index pages
|
||||
Object.values(postsByAuthor).forEach(author => {
|
||||
const authorDir = path.join(AUTHORS_DIR, author.slug);
|
||||
|
||||
if (!fs.existsSync(authorDir)) {
|
||||
fs.mkdirSync(authorDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Generate author index page
|
||||
const frontmatter = {
|
||||
title: `Lise des articles de ${author.name}`,
|
||||
type: 'authors',
|
||||
layout: 'list',
|
||||
author: author.name,
|
||||
author_slug: author.slug
|
||||
};
|
||||
|
||||
const content = `---
|
||||
${Object.entries(frontmatter)
|
||||
.map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
|
||||
.join('\n')}
|
||||
---
|
||||
`;
|
||||
|
||||
fs.writeFileSync(path.join(authorDir, '_index.md'), content);
|
||||
|
||||
console.log(`✅ Generated author directory: ${author.name} (${author.posts.length} posts)`);
|
||||
});
|
||||
}
|
||||
|
||||
generateContent();
|
||||
Reference in New Issue
Block a user