From 9024c00b1a93611aef5f4049ceaedb0494f4b103 Mon Sep 17 00:00:00 2001 From: arne Date: Sun, 20 Feb 2022 18:10:09 +0100 Subject: [PATCH] 10-print header works :) I had to pin @thi.ng/hiccup to an earlier version because they stopped publishing CommonJS modules. There is [an issue tracking EcmaScript module support in 11ty](https://github.com/11ty/eleventy/issues/836) but it has not been fixed yet and other solutions broke unpredictably by messing with template inheritance. --- .eleventy.js | 2 ++ package.json | 6 ++++- pnpm-lock.yaml | 36 ++++++++++++++++++++++++++ src/_helpers/{header.mjs => header.js} | 10 +++---- src/_includes/posts.njk | 6 ++++- src/_includes/root.njk | 11 ++++---- src/index.njk | 16 +++++++----- 7 files changed, 67 insertions(+), 20 deletions(-) rename src/_helpers/{header.mjs => header.js} (88%) diff --git a/.eleventy.js b/.eleventy.js index 84a03bc..650d0af 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,4 +1,5 @@ const { DateTime } = require('luxon') +const header = require('./src/_helpers/header') module.exports = function (config) { config.setBrowserSyncConfig({ @@ -10,6 +11,7 @@ module.exports = function (config) { // template filters config.addFilter('toJSON', obj => JSON.stringify(obj)) config.addFilter('toISODate', date => DateTime.fromJSDate(date).toISODate()) + config.addFilter('header', header) // returns classes to be used on , given a page's url config.addFilter('pageClasses', url => { diff --git a/package.json b/package.json index 900bd66..2f2fca6 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "build": "pnpm build:sass && pnpm build:eleventy", "watch:eleventy": "eleventy --serve --input=src/", "watch:sass": "ls src/**/*.{scss,sass} 2>/dev/null | entr pnpm build:sass", + "watch": "scripts/serve.sh", "start": "scripts/serve.sh" }, "keywords": [], @@ -17,6 +18,9 @@ "license": "ISC", "devDependencies": { "@11ty/eleventy": "^1.0.0", - "luxon": "^2.3.0" + "@thi.ng/hiccup": "3.6.22", + "lodash": "^4.17.21", + "luxon": "^2.3.0", + "seedrandom": "^3.0.5" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9c1e6dd..5405665 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,11 +2,17 @@ lockfileVersion: 5.3 specifiers: '@11ty/eleventy': ^1.0.0 + '@thi.ng/hiccup': 3.6.22 + lodash: ^4.17.21 luxon: ^2.3.0 + seedrandom: ^3.0.5 devDependencies: '@11ty/eleventy': 1.0.0 + '@thi.ng/hiccup': 3.6.22 + lodash: 4.17.21 luxon: 2.3.0 + seedrandom: 3.0.5 packages: @@ -117,6 +123,28 @@ packages: lodash.deburr: 4.1.0 dev: true + /@thi.ng/api/7.2.0: + resolution: {integrity: sha512-4NcwHXxwPF/JgJG/jSFd9rjfQNguF0QrHvd6e+CEf4T0sFChqetW6ZmJ6/a2X+noDVntgulegA+Bx0HHzw+Tyw==} + dev: true + + /@thi.ng/checks/2.9.11: + resolution: {integrity: sha512-fBvWod32w24JlJsrrOdl+tlx+UNehCORi4rHaJ7l7HH+SEhD/lYTCXOBjwu9D/ztIUjMP5Q+n8cAqI5iPhbvAQ==} + dependencies: + tslib: 2.3.1 + dev: true + + /@thi.ng/errors/1.3.4: + resolution: {integrity: sha512-hTk71OPKnioN349sdj2DAoY+69eSerB3MN4Zwz6mosr1QFzIMkfkNOtBeC+Gm0yi0V0EY5LeBYFgqb3oXbtTbw==} + dev: true + + /@thi.ng/hiccup/3.6.22: + resolution: {integrity: sha512-Ev6SzcjJyNVtvwFcNVRQ4wM2TZQA2gPmJIUOvP5i3q/S2qOnq6L+h7XhDkDV6wAs8gl6eu3KRBbcbTpZabAe7w==} + dependencies: + '@thi.ng/api': 7.2.0 + '@thi.ng/checks': 2.9.11 + '@thi.ng/errors': 1.3.4 + dev: true + /@types/minimatch/3.0.5: resolution: {integrity: sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==} dev: true @@ -1742,6 +1770,10 @@ packages: kind-of: 6.0.3 dev: true + /seedrandom/3.0.5: + resolution: {integrity: sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==} + dev: true + /semver-compare/1.0.0: resolution: {integrity: sha1-De4hahyUGrN+nvsXiPavxf9VN/w=} dev: true @@ -1999,6 +2031,10 @@ packages: resolution: {integrity: sha1-zCAOqyYT9BZtJ/+a/HylbUnfbrQ=} dev: true + /tslib/2.3.1: + resolution: {integrity: sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==} + dev: true + /ua-parser-js/1.0.2: resolution: {integrity: sha512-00y/AXhx0/SsnI51fTc0rLRmafiGOM4/O+ny10Ps7f+j/b8p/ZY11ytMgznXkOVo4GQ+KwQG5UQLkLGirsACRg==} dev: true diff --git a/src/_helpers/header.mjs b/src/_helpers/header.js similarity index 88% rename from src/_helpers/header.mjs rename to src/_helpers/header.js index 0f45e8c..0edff31 100644 --- a/src/_helpers/header.mjs +++ b/src/_helpers/header.js @@ -1,7 +1,7 @@ const crypto = require('crypto') const seedrandom = require('seedrandom') const { range } = require('lodash') -// const { serialize } = require('@thi.ng/hiccup') +const { serialize } = require('@thi.ng/hiccup') /** * Given a pair of coordinates representing the center, returns the cartesian @@ -16,7 +16,7 @@ const { range } = require('lodash') */ const polarToCartesian = (cx, cy, radius, alpha) => [cx + (radius * Math.cos(alpha)), - cy + (radius * Math.cos(alpha))] + cy + (radius * Math.sin(alpha))] /** * Draws an svg arc with the given radius with a center at `c-x` and `c-y`. Note @@ -59,8 +59,8 @@ const tenPrint = content => { return ["svg.ten-print", {"viewBox": `${-radius} ${-radius} ${width + 2*radius} ${height + 2*radius}`, "xmlns": "http://www.w3.org/2000/svg", - "style": "overflow: visible"} - ["style", "path { fill: none; stroke: none; }"] // avoid flash of unstyled content + "style": "overflow: visible"}, + ["style", "path { fill: none; stroke: none; }"], // avoid flash of unstyled content ["g", {"transform": "translate(0.5, 0.5"}, ys.map(y => xs.map(x => { @@ -70,4 +70,4 @@ const tenPrint = content => { )]] } -module.exports = content => content +module.exports = content => serialize(tenPrint(content || '')) diff --git a/src/_includes/posts.njk b/src/_includes/posts.njk index cbd3c4b..f7b0441 100644 --- a/src/_includes/posts.njk +++ b/src/_includes/posts.njk @@ -1,5 +1,9 @@ {% extends "root.njk" %} -{% block navigation %} +{% block sidebar %} +
+
Last change
+
+
← Home {% endblock %} diff --git a/src/_includes/root.njk b/src/_includes/root.njk index 92c5981..7bd6fce 100644 --- a/src/_includes/root.njk +++ b/src/_includes/root.njk @@ -1,21 +1,20 @@ - - {{ page.title }} + {% if data.tite %}{{ data.title }} | {% endif %}{{ page.title }}
-
- +
{{ content | safe }}
diff --git a/src/index.njk b/src/index.njk index b741d77..817ed3c 100644 --- a/src/index.njk +++ b/src/index.njk @@ -1,10 +1,12 @@ {% extends "root.njk" %} -{% block navigation %} -

Recent Posts

- +{% block sidebar %} + {% endblock %}