MCPcopy Create free account
hub / github.com/chhoumann/quickadd / buildFileDisplayInfos

Function buildFileDisplayInfos

src/utils/fileSyntax.ts:296–328  ·  view source on GitHub ↗
(
	files: TFile[],
	metadataCache?: (file: TFile) => CachedMetadata | null,
)

Source from the content-addressed store, hash-verified

294}
295
296export function buildFileDisplayInfos(
297 files: TFile[],
298 metadataCache?: (file: TFile) => CachedMetadata | null,
299): FileDisplayInfo[] {
300 const baseLabels = files.map((file) => {
301 const metadata = metadataCache?.(file) ?? null;
302 const basename = basenameFor(file);
303 const primary =
304 frontmatterTitle(metadata?.frontmatter as Record<string, unknown> | undefined) ??
305 firstLevelHeading(metadata) ??
306 basename;
307 const label = primary === basename
308 ? basename
309 : `${primary} (${basename})`;
310 return { file, primary, label };
311 });
312
313 const counts = new Map<string, number>();
314 for (const { label } of baseLabels) {
315 counts.set(label, (counts.get(label) ?? 0) + 1);
316 }
317
318 return baseLabels.map(({ file, primary, label }) => {
319 const uniqueLabel = (counts.get(label) ?? 0) <= 1
320 ? label
321 : `${label} - ${parentLabel(file)}`;
322 return {
323 primary,
324 secondary: file.path,
325 label: uniqueLabel,
326 };
327 });
328}
329
330/**
331 * Display labels for a folder's files: readable title/H1 labels first, with the

Callers 2

renderNotePathSuggestionFunction · 0.90
buildFileDisplayLabelsFunction · 0.85

Calls 6

basenameForFunction · 0.85
frontmatterTitleFunction · 0.85
firstLevelHeadingFunction · 0.85
parentLabelFunction · 0.85
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected