diff --git a/blog.njk b/blog.njk index ef60589..acd8622 100644 --- a/blog.njk +++ b/blog.njk @@ -11,9 +11,9 @@ permalink: "blog/{% if pagination.pageNumber > 0 %}page/{{ pagination.pageNumber

Blog

- {% set sparklineData = collections.posts | postingFrequency %} - {% if sparklineData %} - Posting frequency over the last 12 months + {% set sparklineSvg = collections.posts | postingFrequency %} + {% if sparklineSvg %} + {{ sparklineSvg | safe }} {% endif %}

diff --git a/eleventy.config.js b/eleventy.config.js index a937c51..8315b69 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -456,7 +456,17 @@ export default function (eleventyConfig) { counts[11 - monthsAgo]++; } } - return counts.join(","); + const max = Math.max(...counts, 1); + const w = 200; + const h = 30; + const pad = 2; + const step = w / (counts.length - 1); + const points = counts.map((v, i) => { + const x = i * step; + const y = h - pad - ((v / max) * (h - pad * 2)); + return `${x.toFixed(1)},${y.toFixed(1)}`; + }).join(" "); + return ``; }); // Collections for different post types