refactor: use CSV path instead of markdown file for spark tables
Switch the spark table resolution logic to use the direct path to the backing CSV file rather than attempting to parse the containing markdown file. This simplifies the lookup process and improves reliability. Also refactor `SparkTableMeta` to store rows as objects keyed by header instead of raw string arrays.
This commit is contained in:
@@ -135,6 +135,7 @@ export function inspectSparkTableCsv(csv: string): string[] | null {
|
||||
export function buildSparkTableCompletion(
|
||||
csv: string,
|
||||
filePath: string,
|
||||
csvPath: string,
|
||||
slugger: Slugger,
|
||||
): SparkTableCompletion | null {
|
||||
const dataHeaders = inspectSparkTableCsv(csv);
|
||||
@@ -156,6 +157,7 @@ export function buildSparkTableCompletion(
|
||||
notation: headers[0],
|
||||
slug: combinedSlug,
|
||||
filePath: basePath,
|
||||
csvPath,
|
||||
headers: dataHeaders,
|
||||
};
|
||||
}
|
||||
@@ -246,7 +248,7 @@ export function scanDirectives(
|
||||
newIndexEntries[resolvedPath] = csv;
|
||||
|
||||
// Collect spark table completion
|
||||
const st = buildSparkTableCompletion(csv, filePath, slugger);
|
||||
const st = buildSparkTableCompletion(csv, filePath, resolvedPath, slugger);
|
||||
if (st) {
|
||||
sparkTables.push(st);
|
||||
}
|
||||
@@ -288,7 +290,7 @@ export function scanDirectives(
|
||||
let csv = index[csvPath] ?? newIndexEntries[csvPath];
|
||||
if (!csv) continue;
|
||||
|
||||
const st = buildSparkTableCompletion(csv, filePath, slugger);
|
||||
const st = buildSparkTableCompletion(csv, filePath, csvPath, slugger);
|
||||
if (!st) continue;
|
||||
|
||||
// Check if data-spark is already set in extra attrs
|
||||
|
||||
@@ -46,8 +46,10 @@ export interface SparkTableCompletion {
|
||||
notation: string;
|
||||
/** Concatenated slug of data column headers */
|
||||
slug: string;
|
||||
/** File path of the containing .md file */
|
||||
/** File path of the containing .md file (without extension) */
|
||||
filePath: string;
|
||||
/** Resolved path to the .csv file backing this spark table */
|
||||
csvPath: string;
|
||||
/** Data column headers for display */
|
||||
headers: string[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user