diff --git a/library b/library index 01e8dab..9fba19f 160000 --- a/library +++ b/library @@ -1 +1 @@ -Subproject commit 01e8dab99c8da15b87076959293ac585438a8464 +Subproject commit 9fba19f5cdbfb78af39a2e0295acda176a17550a diff --git a/site/_globals/helpers.js b/site/_globals/helpers.js index aed350c..ac40ce4 100644 --- a/site/_globals/helpers.js +++ b/site/_globals/helpers.js @@ -1,4 +1,6 @@ const fs = require("fs"); +const { execSync } = require("child_process"); +const path = require("path"); /** * Assemble related patterns by loading the page source from disk @@ -35,6 +37,39 @@ const categoryName = (data) => { return category.data.title; }; +const getPublishedDate = (data) => { + try { + const filePath = data.page.inputPath; + + // Extract pattern name from path (e.g., site/library/visual-hash/index.md -> visual-hash) + const pathParts = filePath.split("/"); + const patternName = pathParts[pathParts.length - 2]; + + // Query git history + const libraryPatternPath = `patterns/${patternName}/index.md`; + const workingDir = path.join(process.cwd(), "library"); + const gitCommand = `git log -1 --format="%ci" -- "${libraryPatternPath}"`; + + const result = execSync(gitCommand, { + cwd: workingDir, + encoding: "utf-8", + }).trim(); + + if (result) { + const date = new Date(result); + return date.toLocaleDateString("en-us"); + } + } catch (error) { + console.warn( + `Could not get git date for pattern ${data.page.inputPath}:`, + error.message + ); + } + + // Fallback to file date + return data.page.date.toLocaleDateString("en-us"); +}; + module.exports = { // environment helper environment: process.env.ELEVENTY_ENV, @@ -45,4 +80,6 @@ module.exports = { relatedPatterns: getRelatedPatterns, categoryName, + + publishedDate: getPublishedDate, };