diff --git a/indiekit.config.mjs b/indiekit.config.mjs index 0f6ce369..6ad7a3ca 100644 --- a/indiekit.config.mjs +++ b/indiekit.config.mjs @@ -1,4 +1,6 @@ import "dotenv/config"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; const mongoUsername = process.env.MONGO_USERNAME || process.env.MONGO_USER || ""; const mongoPassword = process.env.MONGO_PASSWORD || ""; @@ -82,6 +84,11 @@ const activityPubDebugDashboard = const activityPubDebugPassword = process.env.AP_DEBUG_PASSWORD || ""; const activityPubAlsoKnownAs = process.env.AP_ALSO_KNOWN_AS || ""; const redisUrl = process.env.REDIS_URL || ""; +const configDir = path.dirname(fileURLToPath(import.meta.url)); +const homepageContentDir = + process.env.HOMEPAGE_CONTENT_DIR || + process.env.CONTENT_DIR || + path.join(configDir, "content"); let webmentionDomain = process.env.WEBMENTION_IO_DOMAIN; if (!webmentionDomain) { @@ -199,6 +206,7 @@ export default { }, "@rmdes/indiekit-endpoint-homepage": { mountPath: "/homepage", + contentDir: homepageContentDir, }, "@rmdes/indiekit-endpoint-conversations": { mountPath: "/conversations", diff --git a/package.json b/package.json index 5bf25217..8af9a306 100644 --- a/package.json +++ b/package.json @@ -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-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", - "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-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", + "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-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", + "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-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", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], diff --git a/scripts/patch-endpoint-homepage-locales.mjs b/scripts/patch-endpoint-homepage-locales.mjs new file mode 100644 index 00000000..5f37ffa5 --- /dev/null +++ b/scripts/patch-endpoint-homepage-locales.mjs @@ -0,0 +1,219 @@ +import { access, readFile, writeFile } from "node:fs/promises"; +import path from "node:path"; + +const endpointCandidates = [ + "node_modules/@rmdes/indiekit-endpoint-homepage", + "node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-homepage", +]; + +const sourceLocale = "en"; +const targetLocales = ["de"]; + +const deOverrides = { + homepageBuilder: { + tabs: { + builder: "Homepage", + blogSidebar: "Blog-Sidebar", + identity: "Identitaet", + }, + identity: { + title: "Identitaet", + description: + "Konfigurieren Sie Ihr Autorenprofil, Kontaktdaten und Social-Links. Diese ueberschreiben Standardwerte aus Umgebungsvariablen.", + saved: + "Identitaet erfolgreich gespeichert. Aktualisieren Sie Ihre Website, um die Aenderungen zu sehen.", + profile: { + legend: "Profil", + name: { + label: "Name", + hint: "Ihr Anzeigename", + }, + avatar: { + label: "Avatar-URL", + hint: "URL zu Ihrem Avatarbild", + }, + title: { + label: "Titel", + hint: "Berufsbezeichnung oder Untertitel", + }, + pronoun: { + label: "Pronomen", + hint: "z. B. er/ihm, sie/ihr, they/them", + }, + bio: { + label: "Bio", + hint: "Kurze Biografie", + }, + description: { + label: "Website-Beschreibung", + hint: "Beschreibung, die im Hero-Bereich angezeigt wird", + }, + }, + location: { + legend: "Standort", + locality: { + label: "Stadt", + hint: "Stadt oder Ort", + }, + country: { + label: "Land", + }, + org: { + label: "Organisation", + hint: "Unternehmen oder Organisation", + }, + }, + contact: { + legend: "Kontakt", + url: { + label: "URL", + hint: "URL Ihrer persoenlichen Website", + }, + email: { + label: "E-Mail", + }, + keyUrl: { + label: "PGP-Schluessel-URL", + hint: "URL zu Ihrem oeffentlichen PGP-Schluessel", + }, + }, + categories: { + legend: "Website-Kategorien", + tags: { + label: "Kategorien", + hint: + "Kommagetrennte Tags fuer Ihre Website (werden als p-category in Ihrer h-card gerendert)", + }, + }, + social: { + legend: "Social-Links", + description: + "Fuegen Sie Links zu Ihren Social-Profilen hinzu. Diese erscheinen im Hero-Bereich und in der h-card.", + name: { + label: "Name", + }, + url: { + label: "URL", + }, + rel: { + label: "Rel", + }, + icon: { + label: "Icon", + }, + }, + }, + }, +}; + +function isObject(value) { + return Boolean(value) && typeof value === "object" && !Array.isArray(value); +} + +function mergeMissing(target, fallback) { + if (target === undefined) { + return fallback; + } + + if (!isObject(target) || !isObject(fallback)) { + return target; + } + + const merged = { ...target }; + + for (const [key, fallbackValue] of Object.entries(fallback)) { + merged[key] = mergeMissing(merged[key], fallbackValue); + } + + return merged; +} + +function applyOverrides(target, overrides) { + if (!isObject(target) || !isObject(overrides)) { + return target; + } + + const merged = { ...target }; + + for (const [key, value] of Object.entries(overrides)) { + if (isObject(value)) { + const existing = isObject(merged[key]) ? merged[key] : {}; + merged[key] = applyOverrides(existing, value); + continue; + } + + merged[key] = value; + } + + return merged; +} + +async function exists(filePath) { + try { + await access(filePath); + return true; + } catch { + return false; + } +} + +let checkedEndpoints = 0; +let checkedLocales = 0; +let patchedLocales = 0; + +for (const endpointPath of endpointCandidates) { + if (!(await exists(endpointPath))) { + continue; + } + + checkedEndpoints += 1; + + const sourcePath = path.join(endpointPath, "locales", `${sourceLocale}.json`); + + if (!(await exists(sourcePath))) { + continue; + } + + let sourceLocaleJson; + try { + sourceLocaleJson = JSON.parse(await readFile(sourcePath, "utf8")); + } catch { + continue; + } + + for (const locale of targetLocales) { + const localePath = path.join(endpointPath, "locales", `${locale}.json`); + checkedLocales += 1; + + let localeJson = {}; + if (await exists(localePath)) { + try { + localeJson = JSON.parse(await readFile(localePath, "utf8")); + } catch { + localeJson = {}; + } + } + + const merged = mergeMissing(localeJson, sourceLocaleJson); + const patched = locale === "de" ? applyOverrides(merged, deOverrides) : merged; + + if (JSON.stringify(patched) === JSON.stringify(localeJson)) { + continue; + } + + await writeFile(localePath, `${JSON.stringify(patched, null, 2)}\n`, "utf8"); + patchedLocales += 1; + } +} + +if (checkedEndpoints === 0) { + console.log("[postinstall] No homepage endpoint directories found"); +} else if (checkedLocales === 0) { + console.log("[postinstall] No homepage locale files checked"); +} else if (patchedLocales === 0) { + console.log("[postinstall] homepage locale files already patched"); +} else { + console.log( + `[postinstall] Patched homepage locale files in ${patchedLocales}/${checkedLocales} file(s)`, + ); +} \ No newline at end of file diff --git a/start.example.sh b/start.example.sh index b3409c0f..f77a5903 100644 --- a/start.example.sh +++ b/start.example.sh @@ -59,6 +59,7 @@ unset DEBUG /usr/local/bin/node scripts/patch-endpoint-files-upload-route.mjs /usr/local/bin/node scripts/patch-endpoint-files-upload-locales.mjs /usr/local/bin/node scripts/patch-endpoint-activitypub-locales.mjs +/usr/local/bin/node scripts/patch-endpoint-homepage-locales.mjs /usr/local/bin/node scripts/patch-frontend-serviceworker-file.mjs /usr/local/bin/node scripts/patch-conversations-collection-guards.mjs /usr/local/bin/node scripts/patch-indiekit-routes-rate-limits.mjs