141 lines
4.1 KiB
Plaintext
141 lines
4.1 KiB
Plaintext
---
|
|
import { getCollection } from "astro:content";
|
|
import Layout from "../layouts/Layout.astro";
|
|
import Card from "../components/Card.astro";
|
|
|
|
const allHumans = await getCollection("humans");
|
|
|
|
// 1. Tri par date décroissante
|
|
const sortedAll = allHumans.sort(
|
|
(a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime(),
|
|
);
|
|
|
|
// 2. Fonction de calcul de Streak (Série) corrigée
|
|
const getStreak = (name, entries) => {
|
|
// On extrait toutes les dates pour cet utilisateur au format YYYY-MM-DD
|
|
const userDates = entries
|
|
.filter((e) => e.data.name === name)
|
|
.map((e) => new Date(e.data.date).toISOString().split("T")[0]);
|
|
|
|
// On dédoublonne et on trie (plus récent au plus ancien)
|
|
const uniqueDates = [...new Set(userDates)].sort().reverse();
|
|
|
|
let streak = 0;
|
|
let today = new Date();
|
|
// On cale la date de vérification sur aujourd'hui à minuit
|
|
let checkDate = new Date(
|
|
today.getFullYear(),
|
|
today.getMonth(),
|
|
today.getDate(),
|
|
);
|
|
|
|
for (let i = 0; i < 31; i++) {
|
|
const dateStr = checkDate.toISOString().split("T")[0];
|
|
|
|
if (uniqueDates.includes(dateStr)) {
|
|
streak++;
|
|
checkDate.setDate(checkDate.getDate() - 1);
|
|
} else {
|
|
// Tolérance : si pas de note aujourd'hui, on vérifie si la série continue depuis hier
|
|
if (i === 0) {
|
|
checkDate.setDate(checkDate.getDate() - 1);
|
|
const yesterdayStr = checkDate.toISOString().split("T")[0];
|
|
if (uniqueDates.includes(yesterdayStr)) continue;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return streak;
|
|
};
|
|
|
|
// 3. Unicité par utilisateur pour l'affichage (dernière version de chaque profil)
|
|
const latestPerUser = Array.from(
|
|
sortedAll
|
|
.reduce((map, obj) => {
|
|
if (!map.has(obj.data.name)) {
|
|
map.set(obj.data.name, obj);
|
|
}
|
|
return map;
|
|
}, new Map())
|
|
.values(),
|
|
);
|
|
---
|
|
|
|
<Layout title="Derniers Souffles">
|
|
<header class="minimal-header">
|
|
<nav>
|
|
<a href="/collection" class="menu-link">
|
|
<span class="icon">🎴</span> Collection
|
|
</a>
|
|
</nav>
|
|
</header>
|
|
|
|
<main class="hero-flex">
|
|
{
|
|
latestPerUser.map((entry) => {
|
|
// On calcule la streak ICI pour l'envoyer à la carte
|
|
const currentStreak = getStreak(entry.data.name, allHumans);
|
|
|
|
return (
|
|
<div class="card-focus">
|
|
<Card
|
|
frontmatter={entry.data}
|
|
streakCount={currentStreak}
|
|
/>
|
|
<div class="entry-meta">
|
|
<p>
|
|
Dernier souffle :{" "}
|
|
{new Date(entry.data.date).toLocaleDateString(
|
|
"fr-FR",
|
|
)}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
})
|
|
}
|
|
</main>
|
|
</Layout>
|
|
|
|
<style>
|
|
[cite_start]/* Ton CSS existant [cite: 9-23] */
|
|
.minimal-header {
|
|
position: fixed;
|
|
top: 0;
|
|
right: 0;
|
|
padding: 20px 30px;
|
|
z-index: 100;
|
|
}
|
|
.menu-link {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
text-decoration: none;
|
|
color: #1e293b;
|
|
font-family: "Philosopher", serif;
|
|
font-weight: bold;
|
|
background: rgba(255, 255, 255, 0.8);
|
|
padding: 10px 20px;
|
|
border-radius: 50px;
|
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
|
|
backdrop-filter: blur(5px);
|
|
transition: transform 0.2s ease;
|
|
}
|
|
.hero-flex {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
justify-content: center;
|
|
gap: 20px;
|
|
padding: 100px 20px;
|
|
width: 100%;
|
|
min-height: 100vh;
|
|
}
|
|
.card-focus {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
gap: 15px;
|
|
flex: 0 1 320px;
|
|
}
|
|
</style>
|