Author page ok
This commit is contained in:
@@ -6,14 +6,14 @@
|
||||
<h1 class="fw-normal">{{ .Title }}</h1>
|
||||
<ul class="list-inline-dash">
|
||||
{{ if .Params.author }}
|
||||
<li><a href="#">{{ .Params.author }}</a></li>
|
||||
<li><a href="/author/{{ .Params.author | urlize }}">{{ .Params.author }}</a></li>
|
||||
{{ end }}
|
||||
{{ with .Params.categories }}
|
||||
{{ range . }}
|
||||
<li><a href="/categories/{{ . | urlize }}">{{ . }}</a></li>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
<li><a href="#">{{ .Date.Format "Jan 2, 2006" }}</a></li>
|
||||
<li><a href="#">{{ .Date.Format "02/01/2006" }}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div><!-- end row -->
|
||||
|
||||
84
layouts/authors/list.html
Normal file
84
layouts/authors/list.html
Normal file
@@ -0,0 +1,84 @@
|
||||
{{ 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">Articles by {{ $authorName }}</h3>
|
||||
<p class="mt-2">Tous les articles écrits par {{ $authorName }}</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="img-link-box">
|
||||
<a href="{{ .RelPermalink }}">
|
||||
{{ if .Params.featured_image }}
|
||||
<img src="{{ .Params.featured_image }}" alt="{{ .Title }}">
|
||||
{{ else }}
|
||||
<img src="/assets/images/col-1.jpg" alt="{{ .Title }}">
|
||||
{{ end }}
|
||||
</a>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<div class="d-inline-flex">
|
||||
{{ if .Params.categories }}
|
||||
{{ range $index, $category := .Params.categories }}
|
||||
{{ if $index }}, {{ end }}
|
||||
{{ if and (eq (printf "%T" $category) "string") }}
|
||||
<a class="font-family-poppins font-small fw-medium uppercase" href="/categories/{{ $category | urlize }}">{{ $category }}</a>
|
||||
{{ else if and (eq (printf "%T" $category) "map") }}
|
||||
{{ if $category.name }}
|
||||
<a class="font-family-poppins font-small fw-medium uppercase" href="/categories/{{ $category.name | urlize }}">{{ $category.name }}</a>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="d-inline-flex">
|
||||
<span class="font-small">{{ .Date.Format "02/07/2006" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<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 }}
|
||||
@@ -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