Display categories

This commit is contained in:
kbe
2025-08-19 16:06:28 +02:00
parent c84ca1d538
commit ac76ba32f6
6 changed files with 191 additions and 21 deletions

View File

@@ -14,8 +14,8 @@ ignoreLogs = ["warning-goldmark-raw-html"]
languageName = 'French' languageName = 'French'
weight = 1 weight = 1
[taxonomies] # [taxonomies]
category = "categories" # category = "categories"
[markup.goldmark.renderer] [markup.goldmark.renderer]
unsafe = true unsafe = true

View File

@@ -5,7 +5,7 @@
<div class="section-sm bg-gray-lighter"> <div class="section-sm bg-gray-lighter">
<div class="container text-center"> <div class="container text-center">
<h3 class="font-family-playfair">Articles by {{ $authorName }}</h3> <h3 class="font-family-playfair">{{ .Title }}</h3>
<p class="mt-2">Tous les articles écrits par {{ $authorName }}</p> <p class="mt-2">Tous les articles écrits par {{ $authorName }}</p>
</div><!-- end container --> </div><!-- end container -->
</div> </div>

View File

@@ -0,0 +1,34 @@
{{ define "main" }}
{{ $defaultCategory := "General" }}
{{ if .Site.Params.defaultCategory }}{{ $defaultCategory = .Site.Params.defaultCategory }}{{ end }}
<div class="section-sm bg-gray-lighter">
<div class="container text-center">
<h3 class="font-family-playfair">{{ .Title }}</h3>
<p class="mt-3">Cette page répertorie toutes les catégories de notre site, offrant une vue d'ensemble structurée de notre contenu.</p>
</div><!-- end container -->
</div>
<!-- Blog section -->
<div class="section">
<div class="container">
<div class="row g-4">
<div class="col-12 col-sm-10 offset-sm-1 col-md-8 offset-md-2">
{{ range $.Site.Data.wordpress.categories }}
<div class="mb-5">
<div class="mt-4">
<h4><a class="text-link-1" href="{{ .link }}">{{ .name }}</a></h4>
<p>{{ .description | safeHTML }}</p>
<div class="mt-3">
<a class="button-text-1" href="{{ .link }}">Voir la catégorie</a>
</div>
</div>
</div>
{{ if not .IsLast }}<hr class="my-5">{{ end }}
{{ end }}
</div>
</div><!-- end row -->
</div><!-- end container -->
</div>
<!-- end Blog section -->
{{ end }}

56
layouts/pages/list.html Normal file
View File

@@ -0,0 +1,56 @@
{{ define "main" }}
{{ $authorName := .Params.author }}
{{ $authorSlug := .Params.author_slug }}
{{ $authorPosts := where .Site.RegularPages "Params.author" $authorName }}
<div class="section-sm bg-gray-lighter">
<div class="container text-center">
<h3 class="font-family-playfair">{{ .Title }}</h3>
<p class="mt-2">Retrouvez toutes les pages utiles du site ici.</p>
</div><!-- end container -->
</div>
<!-- Blog section -->
<div class="section">
<div class="container">
<div class="row g-4">
<div class="col-12 col-sm-10 offset-sm-1 col-md-8 offset-md-2">
{{ $paginationLimit := 10 }}
{{ if .Site.Params.paginationLimit }}{{ $paginationLimit = .Site.Params.paginationLimit }}{{ end }}
{{ $paginator := .Paginate $authorPosts $paginationLimit }}
{{ if gt (len $authorPosts) 0 }}
{{ range $paginator.Pages }}
<!-- Blog Post box -->
<div class="mb-5">
<div class="mt-4">
<h4><a class="text-link-1" href="{{ .RelPermalink }}">{{ .Title }}</a></h4>
{{ if .Params.excerpt }}
<p>{{ .Params.excerpt }}</p>
{{ else if .Summary }}
<p>{{ .Summary }}</p>
{{ else }}
<p>{{ truncate 200 .Content }}</p>
{{ end }}
<div class="mt-3">
<a class="button-text-1" href="{{ .RelPermalink }}">Lire la suite</a>
</div>
</div>
</div>
<!-- End Blog Post box -->
{{ end }}
<!-- Pagination -->
{{ partial "pagination.html" (dict "Paginator" .Paginator "Page" .) }}
{{ else }}
<div class="text-center py-5">
<h4>Aucun article trouvé</h4>
<p>Aucun article n'a été trouvé pour cet auteur.</p>
</div>
{{ end }}
</div>
</div><!-- end row -->
</div><!-- end container -->
</div>
<!-- end Blog section -->
{{ end }}

View File

@@ -68,12 +68,63 @@ async function generateData() {
modified: page.modified 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 // Save data as JSON files
fs.writeFileSync(path.join(OUTPUT_DIR, 'posts.json'), JSON.stringify(posts, null, 2)); 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)); 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, '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, '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, '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)); 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(`✅ Fetched ${posts.length} posts, ${publishedPages.length} pages, ${categories.length} categories, ${tags.length} tags, ${authors.length} authors`);

View File

@@ -161,22 +161,47 @@ function generateAuthorDirectories(posts) {
fs.mkdirSync(AUTHORS_DIR, { recursive: true }); fs.mkdirSync(AUTHORS_DIR, { recursive: true });
} }
// Group posts by author // Group posts by author using proper author data
const postsByAuthor = {}; const postsByAuthor = {};
posts.forEach(post => { posts.forEach(post => {
const authorName = post._embedded?.author?.[0]?.name || 'Unknown'; const author = post._embedded?.author?.[0];
const authorSlug = authorName.toLowerCase().replace(/\s+/g, '-').replace(/[^\w-]/g, ''); if (author) {
const authorSlug = author.slug;
const authorName = author.name;
if (!postsByAuthor[authorSlug]) { if (!postsByAuthor[authorSlug]) {
postsByAuthor[authorSlug] = { postsByAuthor[authorSlug] = {
name: authorName, id: author.id,
slug: authorSlug, name: authorName,
posts: [] 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 // Create author directories and index pages
@@ -187,13 +212,17 @@ function generateAuthorDirectories(posts) {
fs.mkdirSync(authorDir, { recursive: true }); fs.mkdirSync(authorDir, { recursive: true });
} }
// Generate author index page // Generate author index page with proper metadata
const frontmatter = { const frontmatter = {
title: `Lise des articles de ${author.name}`, title: `Articles de ${author.name}`,
type: 'authors', type: 'authors',
layout: 'list', layout: 'list',
author: author.name, 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 = `--- const content = `---