Display categories
This commit is contained in:
@@ -14,8 +14,8 @@ ignoreLogs = ["warning-goldmark-raw-html"]
|
||||
languageName = 'French'
|
||||
weight = 1
|
||||
|
||||
[taxonomies]
|
||||
category = "categories"
|
||||
# [taxonomies]
|
||||
# category = "categories"
|
||||
|
||||
[markup.goldmark.renderer]
|
||||
unsafe = true
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
<div class="section-sm bg-gray-lighter">
|
||||
<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>
|
||||
</div><!-- end container -->
|
||||
</div>
|
||||
@@ -81,4 +81,4 @@
|
||||
</div><!-- end container -->
|
||||
</div>
|
||||
<!-- end Blog section -->
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
34
layouts/categories/list.html
Normal file
34
layouts/categories/list.html
Normal 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
56
layouts/pages/list.html
Normal 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 }}
|
||||
@@ -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