1+ ---js
2+ // <script >
3+ const eleventyNavigation = {
4+ key: " Series" ,
5+ order: 2 ,
6+ };
7+ const aside = true ;
8+
9+ function pageSeries (collection ){
10+ return Object .keys (collection)
11+ .map ((name ) => ({
12+ name: name,
13+ latestPostDate: new Date (Math .max (... collection[name].map (p => p .date ))),
14+ posts: collection[name],
15+ }))
16+ .sort ((a , b ) => b .latestPostDate - a .latestPostDate );
17+ };
18+ // </script >
119---
2- eleventyNavigation:
3- key: "Series"
4- order: 2
5- aside: true
6- ---
20+ {% css %}
21+ .series-posts {
22+ display: grid;
23+ grid-gap: 1rem;
24+ grid-template-columns: 1fr 1fr 1fr 1fr;
25+ }
26+ .series-post {
27+ display: flex;
28+ flex-direction: column;
29+ gap: 1rem;
30+ padding: 8px;
31+ background-color: var(--bg-color-secondary);
32+ box-shadow: 2px 2px 4px var(--shadow-color);
33+ transition: background-color 0.3s;
34+ }
35+
36+ .series-view-all {
37+ display: flex;
38+ align-items: center;
39+ justify-content: center;
40+ font-weight: bold;
41+ padding: 8px;
42+ background-color: var(--bg-color-secondary);
43+ box-shadow: 2px 2px 4px var(--shadow-color);
44+ transition: background-color 0.3s;
45+ }
46+ h3.series-title {
47+ margin-bottom: 0.5rem;
48+ }
49+ {% endcss %}
750<h1 >Series</h1 >
851
9- <ul >
10- {% for k , posts in collections .series %}
11- {% if posts .length > 0 %}
12- {% set serieUrl %} /series/{{ k | slugify }} /{% endset %}
13- <li ><a href =" {{ serieUrl }}" class =" post-tag" >{{ k }} </a > ({{ posts .length }} )</li >
52+ {% for series in pageSeries (collections .series ) %}
53+ {% if series .posts .length > 0 %}
54+ {% set serieUrl %} /series/{{ series .name | slugify }} /{% endset %}
55+ <h3 class =" series-title" ><a href =" {{ serieUrl }}" >{{ series .name }} </a ></h3 >
56+ <div class =" series-posts" >
57+ {% for post in series .posts .slice (- 3) | reverse %}
58+ <div class =" series-post" >
59+ <a href =" {{ post.url }}" >
60+ <img eleventy:ignore src =" {{ post.data.imageUrl }}" alt =" {{ post.data.title }}" />
61+ {{ post .data .title }}
62+ </a >
63+ </div >
64+ {% endfor %}
65+ {% if series .posts .length > 3 %}
66+ <div class =" series-view-all" >
67+ <a href =" {{ serieUrl }}" >View all {{ series .posts .length }} posts > ;> ; </a >
68+ </div >
69+ {% endif %}
70+ </div >
1471 {% endif %}
15- {% endfor %}
16- </ul >
72+ {% endfor %}
0 commit comments