This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env node
|
||||
// Local patch: self-host attribution box (applied at image build time).
|
||||
//
|
||||
// The AdventureLandOnlyUse license requires a crawlable link back to
|
||||
// https://adventure.land, and the original project should not appear to
|
||||
// support a self-hosted instance. The upstream login/character-selection help
|
||||
// box (htmls/contents/account_help.html) shows "Email, for anything:
|
||||
// hello@adventure.land" from a phrase. This patch points that component at
|
||||
// pages.attribution.self-hosted instead, which ships as
|
||||
// docker/attribution/{en.js,de.json}; all other languages fall back to English.
|
||||
//
|
||||
// The script fails loudly when the upstream phrase is gone or the shipped
|
||||
// catalog is incomplete, so a code update cannot silently drop the attribution.
|
||||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const template = process.argv[2] || "/app/htmls/contents/account_help.html";
|
||||
const app = path.resolve(path.dirname(template), "..", "..");
|
||||
|
||||
const upstream_id = "pages.contents.selection_features.email-for-anything-hello-adventure-land";
|
||||
const phrase_id = "pages.attribution.self-hosted";
|
||||
const license_url = "https://adventure.land";
|
||||
|
||||
function fail(message) {
|
||||
console.error("patch-attribution: " + message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const catalogs = [
|
||||
["en", require(path.join(app, "languages", "en", "attribution.js"))],
|
||||
["de", JSON.parse(fs.readFileSync(path.join(app, "languages", "de", "attribution.json"), "utf8"))],
|
||||
];
|
||||
|
||||
for (const [language, catalog] of catalogs) {
|
||||
const text = catalog[phrase_id];
|
||||
if (typeof text !== "string") fail("missing " + phrase_id + " in languages/" + language + "/attribution");
|
||||
if (!text.includes('href="' + license_url + '"')) {
|
||||
fail("languages/" + language + "/attribution does not link to " + license_url);
|
||||
}
|
||||
}
|
||||
|
||||
const source = fs.readFileSync(template, "utf8");
|
||||
|
||||
if (source.includes('"' + phrase_id + '"')) {
|
||||
console.log("patch-attribution: already applied");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (source.split(upstream_id).length !== 2) {
|
||||
fail("expected exactly one occurrence of " + upstream_id + " in " + template);
|
||||
}
|
||||
|
||||
fs.writeFileSync(template, source.replace(upstream_id, phrase_id));
|
||||
console.log("patch-attribution: applied to " + template);
|
||||
Reference in New Issue
Block a user