Skip to content

Commit 9fba19f

Browse files
committed
Use helper
1 parent 9b82da4 commit 9fba19f

File tree

1 file changed

+1
-37
lines changed

1 file changed

+1
-37
lines changed

patterns/library.11tydata.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,7 @@ module.exports = {
55
layout: "pattern",
66
tags: "pattern",
77
eleventyComputed: {
8-
published: (data) => {
9-
// Use git last modified date for the pattern source file in the library submodule
10-
const { execSync } = require("child_process");
11-
const path = require("path");
12-
13-
try {
14-
// Get the pattern name from the input path
15-
let filePath = data.page.inputPath;
16-
17-
// Extract pattern name from path like site/library/visual-hash/index.md
18-
const pathParts = filePath.split("/");
19-
const patternName = pathParts[pathParts.length - 2]; // Get the directory name before index.md
20-
21-
// Check git history in the library submodule for the original pattern file
22-
const libraryPatternPath = `patterns/${patternName}/index.md`;
23-
const workingDir = path.join(process.cwd(), "library");
24-
const gitCommand = `git log -1 --format="%ci" -- "${libraryPatternPath}"`;
25-
26-
const result = execSync(gitCommand, {
27-
cwd: workingDir,
28-
encoding: "utf-8",
29-
}).trim();
30-
31-
if (result) {
32-
const date = new Date(result);
33-
return date.toLocaleDateString("en-us");
34-
}
35-
} catch (error) {
36-
console.warn(
37-
`Could not get git date for pattern ${data.page.inputPath}:`,
38-
error.message
39-
);
40-
}
41-
42-
// Fallback to file date
43-
return data.page.date.toLocaleDateString("en-us");
44-
},
8+
published: (data) => data.helpers.publishedDate(data),
459
relatedPatterns: (data) => data.helpers.relatedPatterns(data),
4610
categoryName: (data) => data.helpers.categoryName(data),
4711
},

0 commit comments

Comments
 (0)