MCPcopy
hub / github.com/callumalpass/tasknotes / extractNoteInfo

Function extractNoteInfo

src/utils/helpers.ts:514–601  ·  view source on GitHub ↗
(
	app: App,
	content: string,
	path: string,
	file?: TFile,
	fieldMapper?: FieldMapper
)

Source from the content-addressed store, hash-verified

512 * Extracts note information from a note file's content
513 */
514export function extractNoteInfo(
515 app: App,
516 content: string,
517 path: string,
518 file?: TFile,
519 fieldMapper?: FieldMapper
520): {
521 title: string;
522 tags: string[];
523 path: string;
524 createdDate?: string;
525 lastModified?: number;
526} | null {
527 let title = path.split("/").pop()?.replace(".md", "") || "Untitled";
528 let tags: string[] = [];
529 let createdDate: string | undefined = undefined;
530 let lastModified: number | undefined = file?.stat.mtime;
531
532 // Try to extract note info from frontmatter using native metadata cache
533 if (file) {
534 const metadata = app.metadataCache.getFileCache(file);
535 const frontmatter = metadata?.frontmatter;
536
537 if (frontmatter) {
538 if (frontmatter.title) {
539 title = frontmatter.title;
540 }
541
542 if (frontmatter.tags && Array.isArray(frontmatter.tags)) {
543 tags = frontmatter.tags;
544 }
545
546 // Extract creation date using field mapper if available
547 if (fieldMapper) {
548 const dateCreatedField = fieldMapper.toUserField("dateCreated");
549 if (frontmatter[dateCreatedField]) {
550 createdDate = frontmatter[dateCreatedField];
551 }
552 } else {
553 // Fallback to common field names when no field mapper provided
554 if (frontmatter.dateCreated) {
555 createdDate = frontmatter.dateCreated;
556 } else if (frontmatter.created) {
557 createdDate = frontmatter.created;
558 }
559 }
560 }
561 }
562
563 // Look for first heading in the content as a fallback title
564 if (title === "Untitled") {
565 const headingMatch = content.match(/^#\s+(.+)$/m);
566 if (headingMatch && headingMatch[1]) {
567 title = headingMatch[1].trim();
568 }
569 }
570
571 // If no creation date in frontmatter, use file creation time

Callers 1

helpers.test.tsFile · 0.90

Calls 4

parseDateToLocalFunction · 0.90
getFileCacheMethod · 0.80
errorMethod · 0.80
toUserFieldMethod · 0.65

Tested by

no test coverage detected