Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library
37 changes: 37 additions & 0 deletions site/_globals/helpers.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +17,7 @@
try {
return [...content.matchAll(regex)].map((m) => m[1]);
} catch (err) {
console.error(

Check warning on line 20 in site/_globals/helpers.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

site/_globals/helpers.js#L20

[no-console] Unexpected console statement.
`Error extracting related patterns: malformed wikilink (${err})`
);
return [];
Expand All @@ -35,6 +37,39 @@
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(

Check warning on line 63 in site/_globals/helpers.js

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

site/_globals/helpers.js#L63

[no-console] Unexpected console statement.
`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,
Expand All @@ -45,4 +80,6 @@
relatedPatterns: getRelatedPatterns,

categoryName,

publishedDate: getPublishedDate,
};
Loading