refactor: improve column slug extraction logic

This commit is contained in:
hypercross 2026-07-07 19:05:47 +08:00
parent 2f29f8774d
commit 97148aa010
1 changed files with 12 additions and 11 deletions

View File

@ -13,16 +13,10 @@
*/ */
import { z } from "zod"; import { z } from "zod";
import { Show, For } from "solid-js"; import { For } from "solid-js";
import { registerMessageType } from "../registry"; import { registerMessageType } from "../registry";
import { rollFormula } from "../../md-commander/hooks"; import { rollFormula } from "../../md-commander/hooks";
import { import { findSparkTable, rollSparkTable } from "../../utils/spark-table";
findSparkTable,
rollSparkTable,
parseMarkdownTables,
isSparkTable,
sparkTableSlug,
} from "../../utils/spark-table";
import { getIndexedData } from "../../../data-loader/file-index"; import { getIndexedData } from "../../../data-loader/file-index";
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -78,9 +72,16 @@ export async function resolveSparkPayload(raw: {
key: string; key: string;
filePath: string; filePath: string;
}): Promise<SparkPayload> { }): Promise<SparkPayload> {
// key is "pageName-columnSlug"; columnSlug is the part after the first "-" // key is "pageName-columnSlug". The page name is the last segment of
const dashIdx = raw.key.indexOf("-"); // filePath (e.g. "01-dry-dock" from "/ayi-games/.../01-dry-dock").
const columnSlug = dashIdx === -1 ? raw.key : raw.key.slice(dashIdx + 1); // Strip it from the key to recover the column slug.
const pathParts = raw.filePath.replace(/^\//, "").split("/");
const pageName = pathParts[pathParts.length - 1] || raw.filePath;
const columnSlug =
raw.key.length > pageName.length + 1 && raw.key.startsWith(pageName + "-")
? raw.key.slice(pageName.length + 1)
: raw.key;
const filePath = `/${raw.filePath.replace(/^\//, "")}`; const filePath = `/${raw.filePath.replace(/^\//, "")}`;
let content: string; let content: string;