first commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import fs from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
const CONTENT_ROOT = path.join(process.cwd(), "content", "zhouyi", "docs");
|
||||
|
||||
export async function readGuaMarkdown(guaMark: string): Promise<string> {
|
||||
const filePath = path.join(CONTENT_ROOT, guaMark, "index.md");
|
||||
return fs.readFile(filePath, "utf-8");
|
||||
}
|
||||
|
||||
export function extractZhangMingRen(guaDetail: string): string | undefined {
|
||||
return guaDetail
|
||||
.match(/(\*\*台灣張銘仁[\s\S]*?)(?=周易第\d+卦)/)?.[1]
|
||||
?.replaceAll("\n\n", "\n");
|
||||
}
|
||||
|
||||
export function extractChangeDetails(
|
||||
guaDetail: string,
|
||||
guaChange: string,
|
||||
guaTitle: string,
|
||||
): string[] {
|
||||
const changeList: string[] = [];
|
||||
if (guaChange === "无变爻") {
|
||||
return changeList;
|
||||
}
|
||||
|
||||
guaChange
|
||||
.split(":")[1]
|
||||
.trim()
|
||||
.split(",")
|
||||
.forEach((change) => {
|
||||
const detail = guaDetail
|
||||
.match(`(\\*\\*${change}變卦[\\s\\S]*?)(?=${guaTitle}|$)`)?.[1]
|
||||
?.replaceAll("\n\n", "\n");
|
||||
if (detail) {
|
||||
changeList.push(detail.trim());
|
||||
}
|
||||
});
|
||||
|
||||
return changeList;
|
||||
}
|
||||
Reference in New Issue
Block a user