Patch Eleventy preset with default AI frontmatter
This commit is contained in:
+2
-2
@@ -4,8 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs && node scripts/patch-endpoint-media-sharp-runtime.mjs && node scripts/patch-frontend-sharp-runtime.mjs && node scripts/patch-endpoint-files-upload-route.mjs && node scripts/patch-endpoint-files-upload-locales.mjs && node scripts/patch-endpoint-activitypub-locales.mjs && node scripts/patch-endpoint-activitypub-docloader-loglevel.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-frontend-serviceworker-file.mjs && node scripts/patch-conversations-collection-guards.mjs && node scripts/patch-conversations-mastodon-disconnect.mjs && node scripts/patch-indiekit-routes-rate-limits.mjs && node scripts/patch-indiekit-error-production-stack.mjs && node scripts/patch-indieauth-devmode-guard.mjs && node scripts/patch-listening-endpoint-runtime-guards.mjs",
|
"postinstall": "node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs && node scripts/patch-endpoint-media-sharp-runtime.mjs && node scripts/patch-frontend-sharp-runtime.mjs && node scripts/patch-endpoint-files-upload-route.mjs && node scripts/patch-endpoint-files-upload-locales.mjs && node scripts/patch-endpoint-activitypub-locales.mjs && node scripts/patch-endpoint-activitypub-docloader-loglevel.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-preset-eleventy-ai-frontmatter.mjs && node scripts/patch-frontend-serviceworker-file.mjs && node scripts/patch-conversations-collection-guards.mjs && node scripts/patch-conversations-mastodon-disconnect.mjs && node scripts/patch-indiekit-routes-rate-limits.mjs && node scripts/patch-indiekit-error-production-stack.mjs && node scripts/patch-indieauth-devmode-guard.mjs && node scripts/patch-listening-endpoint-runtime-guards.mjs",
|
||||||
"serve": "export NODE_ENV=${NODE_ENV:-production} INDIEKIT_DEBUG=${INDIEKIT_DEBUG:-0} && node scripts/preflight-production-security.mjs && node scripts/preflight-mongo-connection.mjs && node scripts/preflight-activitypub-rsa-key.mjs && node scripts/preflight-activitypub-profile-urls.mjs && node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs && node scripts/patch-endpoint-media-sharp-runtime.mjs && node scripts/patch-frontend-sharp-runtime.mjs && node scripts/patch-endpoint-files-upload-route.mjs && node scripts/patch-endpoint-files-upload-locales.mjs && node scripts/patch-endpoint-activitypub-locales.mjs && node scripts/patch-endpoint-activitypub-docloader-loglevel.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-frontend-serviceworker-file.mjs && node scripts/patch-conversations-collection-guards.mjs && node scripts/patch-conversations-mastodon-disconnect.mjs && node scripts/patch-indiekit-routes-rate-limits.mjs && node scripts/patch-indiekit-error-production-stack.mjs && node scripts/patch-indieauth-devmode-guard.mjs && node scripts/patch-listening-endpoint-runtime-guards.mjs && node node_modules/@indiekit/indiekit/bin/cli.js serve --config indiekit.config.mjs",
|
"serve": "export NODE_ENV=${NODE_ENV:-production} INDIEKIT_DEBUG=${INDIEKIT_DEBUG:-0} && node scripts/preflight-production-security.mjs && node scripts/preflight-mongo-connection.mjs && node scripts/preflight-activitypub-rsa-key.mjs && node scripts/preflight-activitypub-profile-urls.mjs && node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs && node scripts/patch-endpoint-media-sharp-runtime.mjs && node scripts/patch-frontend-sharp-runtime.mjs && node scripts/patch-endpoint-files-upload-route.mjs && node scripts/patch-endpoint-files-upload-locales.mjs && node scripts/patch-endpoint-activitypub-locales.mjs && node scripts/patch-endpoint-activitypub-docloader-loglevel.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-preset-eleventy-ai-frontmatter.mjs && node scripts/patch-frontend-serviceworker-file.mjs && node scripts/patch-conversations-collection-guards.mjs && node scripts/patch-conversations-mastodon-disconnect.mjs && node scripts/patch-indiekit-routes-rate-limits.mjs && node scripts/patch-indiekit-error-production-stack.mjs && node scripts/patch-indieauth-devmode-guard.mjs && node scripts/patch-listening-endpoint-runtime-guards.mjs && node node_modules/@indiekit/indiekit/bin/cli.js serve --config indiekit.config.mjs",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import { access, readFile, writeFile } from "node:fs/promises";
|
||||||
|
|
||||||
|
const candidates = [
|
||||||
|
"node_modules/@rmdes/indiekit-preset-eleventy/lib/post-template.js",
|
||||||
|
"node_modules/@indiekit/preset-eleventy/lib/post-template.js",
|
||||||
|
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-preset-eleventy/lib/post-template.js",
|
||||||
|
"node_modules/@indiekit/indiekit/node_modules/@indiekit/preset-eleventy/lib/post-template.js",
|
||||||
|
];
|
||||||
|
|
||||||
|
const patchMarker = "Normalize AI disclosure metadata and default to no AI usage.";
|
||||||
|
|
||||||
|
const oldBlock = [
|
||||||
|
" // Convert url to Eleventy permalink so generated URL matches Indiekit's stored URL",
|
||||||
|
" // Add trailing slash to generate /path/index.html instead of /path.html",
|
||||||
|
" if (properties.url) {",
|
||||||
|
" const url = properties.url;",
|
||||||
|
" properties.permalink = url.endsWith(\"/\") ? url : `${url}/`;",
|
||||||
|
" }",
|
||||||
|
" delete properties.url;",
|
||||||
|
"",
|
||||||
|
" const frontMatter = YAML.stringify(properties, { lineWidth: 0 });",
|
||||||
|
" return `---\\n${frontMatter}---\\n`;",
|
||||||
|
"};",
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
const newBlock = [
|
||||||
|
" // Convert url to Eleventy permalink so generated URL matches Indiekit's stored URL",
|
||||||
|
" // Add trailing slash to generate /path/index.html instead of /path.html",
|
||||||
|
" if (properties.url) {",
|
||||||
|
" const url = properties.url;",
|
||||||
|
" properties.permalink = url.endsWith(\"/\") ? url : `${url}/`;",
|
||||||
|
" }",
|
||||||
|
" delete properties.url;",
|
||||||
|
"",
|
||||||
|
" // Normalize AI disclosure metadata and default to no AI usage.",
|
||||||
|
" const aiSource =",
|
||||||
|
" properties.ai && typeof properties.ai === \"object\" && !Array.isArray(properties.ai)",
|
||||||
|
" ? properties.ai",
|
||||||
|
" : {};",
|
||||||
|
"",
|
||||||
|
" const aiTextLevel = String(",
|
||||||
|
" aiSource.textLevel ?? aiSource.aiTextLevel ?? properties.aiTextLevel ?? \"0\",",
|
||||||
|
" );",
|
||||||
|
"",
|
||||||
|
" const aiCodeLevel = String(",
|
||||||
|
" aiSource.codeLevel ?? aiSource.aiCodeLevel ?? properties.aiCodeLevel ?? \"0\",",
|
||||||
|
" );",
|
||||||
|
"",
|
||||||
|
" const aiTools = aiSource.aiTools ?? aiSource.tools ?? properties.aiTools;",
|
||||||
|
"",
|
||||||
|
" const aiDescription =",
|
||||||
|
" aiSource.aiDescription ?? aiSource.description ?? properties.aiDescription;",
|
||||||
|
"",
|
||||||
|
" delete properties.ai;",
|
||||||
|
" delete properties.aiTextLevel;",
|
||||||
|
" delete properties.aiCodeLevel;",
|
||||||
|
" delete properties.aiTools;",
|
||||||
|
" delete properties.aiDescription;",
|
||||||
|
"",
|
||||||
|
" const frontMatter = YAML.stringify(properties, { lineWidth: 0 });",
|
||||||
|
"",
|
||||||
|
" let aiFrontMatter = `ai:\\n textLevel: \\\"${aiTextLevel}\\\"\\n codeLevel: \\\"${aiCodeLevel}\\\"\\n # aiTools: \\\"Claude, ChatGPT, Copilot\\\"\\n # aiDescription: \\\"Optional disclosure about how AI was used\\\"\\n`;",
|
||||||
|
"",
|
||||||
|
" if (aiTools !== undefined && aiTools !== null && aiTools !== \"\") {",
|
||||||
|
" aiFrontMatter = aiFrontMatter.replace(",
|
||||||
|
" ' # aiTools: \\\"Claude, ChatGPT, Copilot\\\"\\n',",
|
||||||
|
" ` aiTools: ${JSON.stringify(String(aiTools))}\\n`,",
|
||||||
|
" );",
|
||||||
|
" }",
|
||||||
|
"",
|
||||||
|
" if (aiDescription !== undefined && aiDescription !== null && aiDescription !== \"\") {",
|
||||||
|
" aiFrontMatter = aiFrontMatter.replace(",
|
||||||
|
" ' # aiDescription: \\\"Optional disclosure about how AI was used\\\"\\n',",
|
||||||
|
" ` aiDescription: ${JSON.stringify(String(aiDescription))}\\n`,",
|
||||||
|
" );",
|
||||||
|
" }",
|
||||||
|
"",
|
||||||
|
" return `---\\n${frontMatter}${aiFrontMatter}---\\n`;",
|
||||||
|
"};",
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
async function exists(filePath) {
|
||||||
|
try {
|
||||||
|
await access(filePath);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let checked = 0;
|
||||||
|
let patched = 0;
|
||||||
|
|
||||||
|
for (const filePath of candidates) {
|
||||||
|
if (!(await exists(filePath))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
checked += 1;
|
||||||
|
|
||||||
|
const source = await readFile(filePath, "utf8");
|
||||||
|
|
||||||
|
if (source.includes(patchMarker)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!source.includes(oldBlock)) {
|
||||||
|
console.warn(
|
||||||
|
`[postinstall] Skipping preset-eleventy AI frontmatter patch for ${filePath}: upstream format changed`,
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = source.replace(oldBlock, newBlock);
|
||||||
|
await writeFile(filePath, updated, "utf8");
|
||||||
|
patched += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checked === 0) {
|
||||||
|
console.log("[postinstall] No preset-eleventy post-template files found");
|
||||||
|
} else if (patched === 0) {
|
||||||
|
console.log("[postinstall] preset-eleventy AI frontmatter patch already applied");
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`[postinstall] Patched preset-eleventy AI frontmatter in ${patched} file(s)`,
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user