From 384a8667efef4c493e0f407dbaa280d57425f039 Mon Sep 17 00:00:00 2001 From: arne Date: Mon, 22 Jul 2024 21:45:21 +0200 Subject: [PATCH] Fix dates on gardening page --- src/_includes/helpers/git.js | 21 +++++++++++++++++++++ src/gardening/gardening.11tydata.js | 5 +++++ src/gardening/index.md | 3 ++- src/posts/posts.11tydata.js | 24 ++---------------------- 4 files changed, 30 insertions(+), 23 deletions(-) create mode 100644 src/_includes/helpers/git.js diff --git a/src/_includes/helpers/git.js b/src/_includes/helpers/git.js new file mode 100644 index 0000000..3b13072 --- /dev/null +++ b/src/_includes/helpers/git.js @@ -0,0 +1,21 @@ +import { promisify } from 'node:util' +import { exec as _exec } from 'node:child_process' +const exec = promisify(_exec) + +const commitFromLog = message => { + if (message === '') return {} + + const [ commit, author, date, _, msg ] = message.split('\n') + + return { + hash: commit.replace(/^commit /, ''), + author: author.replace(/^Author:\s*/, ''), + date: new Date(date.replace(/^Date:\s*/, '')), + message: msg.trim() + } +} + +export const latestCommitFor = async file => { + const { stdout } = await exec(`git log -n 1 --pretty=medium --date=iso -- ${file}`) + return commitFromLog(stdout) +} diff --git a/src/gardening/gardening.11tydata.js b/src/gardening/gardening.11tydata.js index 4bd301b..f142d00 100644 --- a/src/gardening/gardening.11tydata.js +++ b/src/gardening/gardening.11tydata.js @@ -1,6 +1,8 @@ import { env } from 'node:process' import eleventyFetch from '@11ty/eleventy-fetch' +import { latestCommitFor } from '../_includes/helpers/git.js' + const { MB_DATA_URL, LB_DATA_URL, OSM_DATA_URL } = env const osmChangeSets = async (baseUrl) => { @@ -50,5 +52,8 @@ export default async (_) => { listenBrainz, musicBrainz, openStreetMap, + eleventyComputed: { + commit: async data => await latestCommitFor(data.page.inputPath) + } } } diff --git a/src/gardening/index.md b/src/gardening/index.md index 84592d5..5689caf 100644 --- a/src/gardening/index.md +++ b/src/gardening/index.md @@ -1,11 +1,12 @@ --- +date: Git created title: Gardening the commons --- # Gardening the commons This page holds information about open data platforms that I participate in. Text that is marked `like this` will update whenever this site is rebuilt. -I have submitted `{{ musicBrainz.edits.total }}` edits to [MusicBrainz](https://musicbrainz.org/), adding `{{ musicBrainz.addedEntities.coverArt }}` pieces of cover art, `{{ musicBrainz.addedEntities.release }}` releases and `{{ musicBrainz.addedEntities.artist }}` artists which now exist in the database. Music is something deeply personal for me and it feels good to know that work I put into furthering information about the music I like is available in the public domain. Oftentimes these submissions are directly related to the artists and songs I listen to, of which I tracked `{{ listenBrainz.total }}` on [ListenBrainz](https://listenbrainz.org/). My listening history goes back to `{{ listenBrainz.firstYear }}`, and I have even created a Markov-Chain based playlist generation tool by exporting it to SQLite. Maybe I'll write about that some time. +I have submitted `{{ musicBrainz.edits.total }}` edits to [MusicBrainz](https://musicbrainz.org/), adding `{{ musicBrainz.addedEntities.coverArt }}` pieces of cover art, `{{ musicBrainz.addedEntities.release }}` releases and `{{ musicBrainz.addedEntities.artist }}` artists to the database. Music is something deeply personal for me and it feels good to know that work I put into furthering information about the music I like is available in the public domain. Oftentimes these submissions are directly related to the artists and songs I listen to, of which I tracked `{{ listenBrainz.total }}` on [ListenBrainz](https://listenbrainz.org/). My listening history goes back to `{{ listenBrainz.firstYear }}`, and I have even created a Markov-Chain based playlist generation tool by exporting it to SQLite. Maybe I'll write about that some time. [OpenStreetMap](https://www.openstreetmap.org/) is one other place I regularly submit data to. I use different apps to navigate using OpenStreetMap data and to find my way around when I'm somewhere I don't know well. I have added `{{ openStreetMap.changesets.length }}` changes, many of which were locations of benches or water fountains — things I found useful when being outside. For this I mostly use [OsmAnd](https://osmand.net/) (`{{ openStreetMap.stats.doneInOsmand }}` times). It's an Android application that has very many toggles and switches for a map application. I have also completed `{{ openStreetMap.stats.doneInStreetComplete }}` quests in [StreetComplete](https://streetcomplete.app/), which prompts you with tasks to complete map data around you. It's very fun. Common topics are questions around accessibility, lighting conditions, public transit or more generally outside amenities. diff --git a/src/posts/posts.11tydata.js b/src/posts/posts.11tydata.js index 8c9d430..bc02337 100644 --- a/src/posts/posts.11tydata.js +++ b/src/posts/posts.11tydata.js @@ -1,31 +1,11 @@ -import { promisify } from 'node:util' -import { exec as _exec } from 'node:child_process' -const exec = promisify(_exec) - -const commitFromLog = message => { - if (message === '') return {} - - const [ commit, author, date, _, msg ] = message.split('\n') - - return { - hash: commit.replace(/^commit /, ''), - author: author.replace(/^Author:\s*/, ''), - date: new Date(date.replace(/^Date:\s*/, '')), - message: msg.trim() - } -} - -const lastCommitFor = async file => { - const { stdout } = await exec(`git log -n 1 --pretty=medium --date=iso -- ${file}`) - return commitFromLog(stdout) -} +import { latestCommitFor } from '../_includes/helpers/git.js' export default async (_) => { return { tags: "posts", layout: "posts.njk", eleventyComputed: { - commit: async data => await lastCommitFor(data.page.inputPath) + commit: async data => await latestCommitFor(data.page.inputPath) } } }