feat: add local hexagram content for offline reading

Load a versioned Wikisource jing plus project-authored plain drafts so results can show labeled original and vernacular texts without unauthorized modern translations.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
QiuSW
2026-08-19 11:48:16 +08:00
co-authored by Cursor
parent 4235cf9011
commit 534c88993e
33 changed files with 5626 additions and 29 deletions
+49
View File
@@ -104,3 +104,52 @@ for (const [name, mutate, expected] of negativeCases) {
console.log(
`Content contract verification passed (64 entries cross-checked with Kotlin, ${negativeCases.length} negative fixtures, digest ${digest.slice(0, 12)}…).`,
);
const packagePath = path.join(repositoryRoot, "content", "packages", "hexagram-content.json");
const namesPath = path.join(
repositoryRoot,
"app",
"src",
"main",
"java",
"net",
"opcapp",
"flash",
"core",
"model",
"HexagramNames.kt",
);
const namesSource = await readFile(namesPath, "utf8");
const namesBlock = namesSource.match(/private val names = listOf\(([\s\S]*?)\)/u);
if (!namesBlock) {
throw new Error("HexagramNames.kt name table could not be parsed");
}
const catalogNames = [...namesBlock[1].matchAll(/"([^"]+)"/gu)].map((match) => match[1]);
if (catalogNames.length !== 64) {
throw new Error("HexagramNames.kt must contain 64 names");
}
const published = JSON.parse(await readFile(packagePath, "utf8"));
const publishedErrors = validateContentPackage(published);
if (publishedErrors.length > 0) {
throw new Error(`Published content package failed validation:\n${publishedErrors.join("\n")}`);
}
published.hexagrams.forEach((hexagram) => {
const expectedName = catalogNames[hexagram.kingWenNumber - 1];
const expectedSymbol = String.fromCodePoint(0x4DC0 + hexagram.kingWenNumber - 1);
if (hexagram.name !== expectedName) {
throw new Error(`Published package name for ${hexagram.kingWenNumber} must be ${expectedName}`);
}
if (hexagram.symbol !== expectedSymbol) {
throw new Error(`Published package symbol for ${hexagram.kingWenNumber} must be ${expectedSymbol}`);
}
});
if (published.contentVersion !== "zh-Hans-2026.1") {
throw new Error("Published contentVersion must be zh-Hans-2026.1");
}
if (!published.specialUsageTexts.qian || !published.specialUsageTexts.kun) {
throw new Error("Published package must include Qian 用九 and Kun 用六");
}
console.log(
`Published content package ${published.contentVersion} passed (digest ${contentDigest(published).slice(0, 12)}…).`,
);