Merge pull request #1 from AriTheStupidCat/metadata-fix

Metadata fix
This commit is contained in:
Ari 2026-06-15 01:27:47 +01:00 committed by GitHub
commit a78dac9830
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 9 deletions

View File

@ -142,6 +142,6 @@
<script src="/js/flavors.js"></script> <script src="/js/flavors.js"></script>
<script src="/js/cat.js"></script> <script src="/js/cat.js"></script>
<script src="/js/heatmap.js"></script> <script src="/js/heatmap.js"></script>
<script>ContribHeatmap.render("#contrib", { theme: "trans" });</script> <script>ContribHeatmap.render("#contrib", { theme: "forest" });</script>
</html> </html>

View File

@ -238,6 +238,5 @@
<script src="/js/flavors.js"></script> <script src="/js/flavors.js"></script>
<script src="/js/cat.js"></script> <script src="/js/cat.js"></script>
<script src="/js/heatmap.js"></script> <script src="/js/heatmap.js"></script>
<script>ContribHeatmap.render("#contrib", { theme: "trans" });</script>
</html> </html>

View File

@ -123,6 +123,4 @@
<script src="/js/flavors.js"></script> <script src="/js/flavors.js"></script>
<script src="/js/cat.js"></script> <script src="/js/cat.js"></script>
<script src="/js/heatmap.js"></script> <script src="/js/heatmap.js"></script>
<script>ContribHeatmap.render("#contrib", { theme: "trans" });</script>
</html> </html>

View File

@ -1,7 +1,7 @@
(function (global) { (function (global) {
"use strict"; "use strict";
/* ---- core logic (unchanged from the working version) ---- */ /* ---- core logic ---- */
function sundayOf(date) { function sundayOf(date) {
const sunday = new Date(date); const sunday = new Date(date);
sunday.setUTCDate(sunday.getUTCDate() - sunday.getUTCDay()); sunday.setUTCDate(sunday.getUTCDate() - sunday.getUTCDay());
@ -28,6 +28,19 @@
} }
return week; return week;
} }
// The current week is truncated to "today" (per the viewer's clock) so future
// cells don't render. But the data source has its own clock; if it reports a
// contribution dated later in the current week than the viewer's clock thinks
// "now" is, that day's index lands past the truncated array. Grow the week to
// fit any real data point instead of writing off the end (week[idx] undefined).
function ensureDay(week, idx) {
while (week.length <= idx) {
const date = new Date(week[0].date + "T00:00:00Z");
date.setUTCDate(date.getUTCDate() + week.length);
week.push({ sources: {}, contributions: 0, date: date.toISOString().slice(0, 10) });
}
return week[idx];
}
function buildHeatmapData(sources) { function buildHeatmapData(sources) {
const weeks = new Map(); const weeks = new Map();
for (const sourceName of Object.keys(sources)) { for (const sourceName of Object.keys(sources)) {
@ -39,9 +52,10 @@
if (day.contributions > 0) { if (day.contributions > 0) {
const week = weeks.get(key); const week = weeks.get(key);
const idx = new Date(day.timestamp * 1000).getUTCDay(); const idx = new Date(day.timestamp * 1000).getUTCDay();
week[idx].contributions += day.contributions; const cell = ensureDay(week, idx);
if (!week[idx].sources[sourceName]) week[idx].sources[sourceName] = 0; cell.contributions += day.contributions;
week[idx].sources[sourceName] += day.contributions; if (!cell.sources[sourceName]) cell.sources[sourceName] = 0;
cell.sources[sourceName] += day.contributions;
} }
} }
} }