feat : sparklines 14j stats + filtre IPs LAN (v1.6.27)
- Admin stats : sparklines SVG par page (120×28 px, courbe + dégradé), carte « Pages les plus visitées » en pleine largeur - AccessLogParser : données par jour (pages_by_day) sur 14 jours - AccessLogParser : IPs privées/LAN exclues de la répartition réseau - ArticleManager : suppression opérateur nullsafe superflu (PHPStan) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,16 +17,39 @@
|
||||
});
|
||||
}());
|
||||
|
||||
// ── Pages les plus visitées (RSS XML) ────────────────────────────────────────
|
||||
// ── Pages les plus visitées (RSS XML + sparklines) ───────────────────────────
|
||||
(function () {
|
||||
var container = document.getElementById('stats-pages-container');
|
||||
var badge = document.getElementById('stats-pages-count');
|
||||
var container = document.getElementById('stats-pages-container');
|
||||
var badge = document.getElementById('stats-pages-count');
|
||||
var pagesByDay = (typeof FOLIO_PAGES_BY_DAY !== 'undefined') ? FOLIO_PAGES_BY_DAY : {};
|
||||
if (!container) { return; }
|
||||
|
||||
function esc(s) {
|
||||
return String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
}
|
||||
|
||||
function sparkline(data) {
|
||||
var W = 120, H = 28, padX = 2, padY = 3;
|
||||
var max = Math.max.apply(null, data) || 1;
|
||||
var n = data.length;
|
||||
var pts = data.map(function (v, i) {
|
||||
var x = padX + i * (W - 2 * padX) / (n - 1);
|
||||
var y = H - padY - (v / max) * (H - 2 * padY);
|
||||
return x.toFixed(1) + ',' + y.toFixed(1);
|
||||
}).join(' ');
|
||||
// Zone remplie sous la courbe
|
||||
var first = padX.toFixed(1) + ',' + (H - padY).toFixed(1);
|
||||
var last = (W - padX).toFixed(1) + ',' + (H - padY).toFixed(1);
|
||||
return '<svg xmlns="http://www.w3.org/2000/svg" width="' + W + '" height="' + H + '" style="display:block;overflow:visible">'
|
||||
+ '<defs><linearGradient id="spk-grad" x1="0" y1="0" x2="0" y2="1">'
|
||||
+ '<stop offset="0%" stop-color="var(--bs-primary,#0d6efd)" stop-opacity="0.18"/>'
|
||||
+ '<stop offset="100%" stop-color="var(--bs-primary,#0d6efd)" stop-opacity="0"/>'
|
||||
+ '</linearGradient></defs>'
|
||||
+ '<polygon points="' + first + ' ' + pts + ' ' + last + '" fill="url(#spk-grad)"/>'
|
||||
+ '<polyline points="' + pts + '" fill="none" stroke="var(--bs-primary,#0d6efd)" stroke-width="1.5" stroke-linejoin="round" stroke-linecap="round"/>'
|
||||
+ '</svg>';
|
||||
}
|
||||
|
||||
fetch('/trending?period=14d')
|
||||
.then(function (r) { return r.ok ? r.text() : Promise.reject(); })
|
||||
.then(function (xml) {
|
||||
@@ -43,19 +66,23 @@
|
||||
var vis = m ? parseInt(m[1], 10) : 0;
|
||||
var title = raw.replace(/\s*\(\d+\s+visiteurs?\)$/, '');
|
||||
var slug = decodeURIComponent(link.replace(/.*\/post\//, ''));
|
||||
return { title: title, link: link, slug: slug, vis: vis };
|
||||
var pm = link.match(/\/post\/[^?#]*/);
|
||||
var daily = pm ? (pagesByDay[pm[0]] || null) : null;
|
||||
return { title: title, link: link, slug: slug, vis: vis, daily: daily };
|
||||
});
|
||||
var maxV = Math.max.apply(null, rows.map(function (r) { return r.vis; })) || 1;
|
||||
var html = '<div class="table-responsive"><table class="table table-sm table-hover mb-0 small"><tbody>';
|
||||
var html = '<div class="table-responsive"><table class="table table-sm table-hover mb-0 small w-100"><tbody>';
|
||||
rows.forEach(function (row, i) {
|
||||
var pct = Math.round(row.vis / maxV * 100);
|
||||
var vis = row.vis.toLocaleString('fr-FR');
|
||||
var vis = row.vis.toLocaleString('fr-FR');
|
||||
var spk = row.daily ? sparkline(row.daily) : '';
|
||||
html += '<tr>'
|
||||
+ '<td class="text-muted ps-3" style="width:2rem">' + (i + 1) + '</td>'
|
||||
+ '<td><a href="' + esc(row.link) + '" target="_blank" class="text-decoration-none text-truncate d-block" style="max-width:260px" title="' + esc(row.slug) + '">'
|
||||
+ esc(row.title || row.slug) + '</a>'
|
||||
+ '<div class="progress mt-1" style="height:3px"><div class="progress-bar" style="width:' + pct + '%"></div></div></td>'
|
||||
+ '<td class="text-end fw-semibold pe-3">' + vis + ' <span class="text-muted fw-normal">vis.</span></td>'
|
||||
+ '<td class="text-muted ps-3" style="width:2rem;vertical-align:middle">' + (i + 1) + '</td>'
|
||||
+ '<td style="vertical-align:middle"><a href="' + esc(row.link) + '" target="_blank"'
|
||||
+ ' class="text-decoration-none" title="' + esc(row.slug) + '">'
|
||||
+ esc(row.title || row.slug) + '</a></td>'
|
||||
+ '<td style="width:130px;vertical-align:middle;padding:4px 8px">' + spk + '</td>'
|
||||
+ '<td class="text-end fw-semibold pe-3" style="width:5rem;vertical-align:middle">'
|
||||
+ vis + ' <span class="text-muted fw-normal">vis.</span></td>'
|
||||
+ '</tr>';
|
||||
});
|
||||
html += '</tbody></table></div>';
|
||||
|
||||
Reference in New Issue
Block a user