Fix homepage SITE_SOCIAL identity defaults parsing

This commit is contained in:
svemagie
2026-03-09 21:23:50 +01:00
parent 31129c48e1
commit 4eb7c07eb3
3 changed files with 212 additions and 2 deletions

View File

@@ -4,8 +4,8 @@
"description": "",
"main": "index.js",
"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-activitypub-private-url-docloader.mjs && node scripts/patch-endpoint-activitypub-migrate-alias-clear.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-endpoint-posts-ai-fields.mjs && node scripts/patch-endpoint-posts-ai-cleanup.mjs && node scripts/patch-endpoint-podroll-opml-upload.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-activitypub-private-url-docloader.mjs && node scripts/patch-endpoint-activitypub-migrate-alias-clear.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-endpoint-posts-ai-fields.mjs && node scripts/patch-endpoint-posts-ai-cleanup.mjs && node scripts/patch-endpoint-podroll-opml-upload.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",
"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-activitypub-private-url-docloader.mjs && node scripts/patch-endpoint-activitypub-migrate-alias-clear.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-endpoint-homepage-identity-defaults.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-endpoint-posts-ai-fields.mjs && node scripts/patch-endpoint-posts-ai-cleanup.mjs && node scripts/patch-endpoint-podroll-opml-upload.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-activitypub-private-url-docloader.mjs && node scripts/patch-endpoint-activitypub-migrate-alias-clear.mjs && node scripts/patch-endpoint-homepage-locales.mjs && node scripts/patch-endpoint-homepage-identity-defaults.mjs && node scripts/patch-federation-unlisted-guards.mjs && node scripts/patch-endpoint-micropub-where-note-visibility.mjs && node scripts/patch-endpoint-posts-ai-fields.mjs && node scripts/patch-endpoint-posts-ai-cleanup.mjs && node scripts/patch-endpoint-podroll-opml-upload.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"
},
"keywords": [],

View File

@@ -0,0 +1,209 @@
import { access, readFile, writeFile } from "node:fs/promises";
const candidates = [
"node_modules/@rmdes/indiekit-endpoint-homepage/lib/controllers/dashboard.js",
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-homepage/lib/controllers/dashboard.js",
];
const marker = "function parseSiteSocialFromEnv(rawValue)";
const oldHelpersBlock = `function parseSocialLinks(body) {
const social = [];
if (!body.social) return social;
const entries = Array.isArray(body.social) ? body.social : Object.values(body.social);
for (const entry of entries) {
if (!entry || (!entry.name && !entry.url)) continue;
social.push({
name: entry.name || "",
url: entry.url || "",
rel: entry.rel || "me",
icon: entry.icon || "",
});
}
return social;
}`;
const newHelpersBlock = `function parseSocialLinks(body) {
const social = [];
if (!body.social) return social;
const entries = Array.isArray(body.social) ? body.social : Object.values(body.social);
for (const entry of entries) {
if (!entry || (!entry.name && !entry.url)) continue;
social.push({
name: entry.name || "",
url: entry.url || "",
rel: entry.rel || "me",
icon: entry.icon || "",
});
}
return social;
}
function normalizeSiteSocialEnvValue(rawValue) {
if (typeof rawValue !== "string") {
return "";
}
let value = rawValue.trim();
if (!value) {
return "";
}
while (/^SITE_SOCIAL\s*=/i.test(value)) {
value = value.replace(/^SITE_SOCIAL\s*=/i, "").trim();
}
if (
(value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))
) {
value = value.slice(1, -1).trim();
} else {
value = value.replace(/^["']+/, "").replace(/["']+$/, "").trim();
}
return value;
}
function parseSiteSocialFromEnv(rawValue) {
const normalized = normalizeSiteSocialEnvValue(rawValue);
if (!normalized) {
return [];
}
return normalized
.split(",")
.map((entry) => entry.trim())
.filter(Boolean)
.map((entry) => {
const parts = entry.split("|").map((part) => part.trim());
if (parts.length < 2) {
return null;
}
const name = parts[0] || "";
const url = parts[1] || "";
let rel = "me";
let icon = "";
if (parts.length >= 4) {
rel = parts[2] || "me";
icon = parts.slice(3).join("|") || "";
} else if (parts.length >= 3) {
icon = parts[2] || "";
}
if (!name && !url) {
return null;
}
return {
name,
url,
rel,
icon,
};
})
.filter(Boolean);
}
function getIdentityDefaultsFromEnv() {
return {
name: (process.env.AUTHOR_NAME || "").trim(),
avatar: (process.env.AUTHOR_AVATAR || "").trim(),
title: "",
pronoun: "",
bio: (process.env.AUTHOR_BIO || "").trim(),
description: (process.env.SITE_DESCRIPTION || "").trim(),
locality: "",
country: "",
org: "",
url: (process.env.PUBLICATION_URL || process.env.SITE_URL || "").trim(),
email: "",
keyUrl: "",
categories: [],
social: parseSiteSocialFromEnv(process.env.SITE_SOCIAL),
};
}
function mergeIdentityDefaults(identity) {
const defaults = getIdentityDefaultsFromEnv();
if (!identity || typeof identity !== "object") {
return defaults;
}
return {
...defaults,
...identity,
categories: Array.isArray(identity.categories)
? identity.categories
: defaults.categories,
social: Array.isArray(identity.social) ? identity.social : defaults.social,
};
}`;
const oldIdentityLine = " const identity = config.identity || {};";
const newIdentityLine = " const identity = mergeIdentityDefaults(config.identity);";
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");
let updated = source;
let changed = false;
if (!updated.includes(marker)) {
if (!updated.includes(oldHelpersBlock)) {
continue;
}
updated = updated.replace(oldHelpersBlock, newHelpersBlock);
changed = true;
}
if (!updated.includes(newIdentityLine)) {
if (!updated.includes(oldIdentityLine)) {
continue;
}
updated = updated.replace(oldIdentityLine, newIdentityLine);
changed = true;
}
if (!changed) {
continue;
}
await writeFile(filePath, updated, "utf8");
patched += 1;
}
if (checked === 0) {
console.log("[postinstall] No endpoint-homepage dashboard controllers found");
} else if (patched === 0) {
console.log("[postinstall] endpoint-homepage identity defaults already patched");
} else {
console.log(
`[postinstall] Patched endpoint-homepage identity defaults in ${patched} file(s)`,
);
}

View File

@@ -291,6 +291,7 @@ unset DEBUG
"${NODE_BIN}" scripts/patch-endpoint-activitypub-private-url-docloader.mjs
"${NODE_BIN}" scripts/patch-endpoint-activitypub-migrate-alias-clear.mjs
"${NODE_BIN}" scripts/patch-endpoint-homepage-locales.mjs
"${NODE_BIN}" scripts/patch-endpoint-homepage-identity-defaults.mjs
"${NODE_BIN}" scripts/patch-frontend-serviceworker-file.mjs
"${NODE_BIN}" scripts/patch-conversations-collection-guards.mjs
"${NODE_BIN}" scripts/patch-indiekit-routes-rate-limits.mjs