( files: TFile[], metadataCache?: (file: TFile) => CachedMetadata | null, )
| 294 | } |
| 295 | |
| 296 | export 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 |
no test coverage detected