diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 41128ba..49040ab 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -6,14 +6,14 @@

{{ .Title }}

diff --git a/layouts/authors/list.html b/layouts/authors/list.html new file mode 100644 index 0000000..b1361b6 --- /dev/null +++ b/layouts/authors/list.html @@ -0,0 +1,84 @@ +{{ define "main" }} +{{ $authorName := .Params.author }} +{{ $authorSlug := .Params.author_slug }} +{{ $authorPosts := where .Site.RegularPages "Params.author" $authorName }} + +
+
+

Articles by {{ $authorName }}

+

Tous les articles écrits par {{ $authorName }}

+
+
+ + +
+
+
+
+ {{ $paginationLimit := 10 }} + {{ if .Site.Params.paginationLimit }}{{ $paginationLimit = .Site.Params.paginationLimit }}{{ end }} + {{ $paginator := .Paginate $authorPosts $paginationLimit }} + + {{ if gt (len $authorPosts) 0 }} + {{ range $paginator.Pages }} + +
+ +
+
+
+ {{ if .Params.categories }} + {{ range $index, $category := .Params.categories }} + {{ if $index }}, {{ end }} + {{ if and (eq (printf "%T" $category) "string") }} + {{ $category }} + {{ else if and (eq (printf "%T" $category) "map") }} + {{ if $category.name }} + {{ $category.name }} + {{ end }} + {{ end }} + {{ end }} + {{ end }} +
+
+ {{ .Date.Format "02/07/2006" }} +
+
+

{{ .Title }}

+ {{ if .Params.excerpt }} +

{{ .Params.excerpt }}

+ {{ else if .Summary }} +

{{ .Summary }}

+ {{ else }} +

{{ truncate 200 .Content }}

+ {{ end }} + +
+
+ + {{ end }} + + + {{ partial "pagination.html" (dict "Paginator" .Paginator "Page" .) }} + {{ else }} +
+

Aucun article trouvé

+

Aucun article n'a été trouvé pour cet auteur.

+
+ {{ end }} +
+
+
+
+ +{{ end }} \ No newline at end of file diff --git a/scripts/generate-content.js b/scripts/generate-content.js index f20e3f9..2951655 100644 --- a/scripts/generate-content.js +++ b/scripts/generate-content.js @@ -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(); \ No newline at end of file