MCPcopy Index your code
hub / github.com/callumalpass/tasknotes / extractTaskInfo

Function extractTaskInfo

src/utils/helpers.ts:299–378  ·  view source on GitHub ↗
(
	app: App,
	content: string,
	path: string,
	file: TFile,
	fieldMapper?: FieldMapper,
	storeTitleInFilename?: boolean,
	defaultStatus?: string
)

Source from the content-addressed store, hash-verified

297 * Extracts task information from a task file's content using field mapping
298 */
299export function extractTaskInfo(
300 app: App,
301 content: string,
302 path: string,
303 file: TFile,
304 fieldMapper?: FieldMapper,
305 storeTitleInFilename?: boolean,
306 defaultStatus?: string
307): TaskInfo | null {
308 // Try to extract task info from frontmatter using native metadata cache
309 const metadata = app.metadataCache.getFileCache(file);
310 const yaml = metadata?.frontmatter;
311
312 if (yaml) {
313 if (fieldMapper) {
314 // Use field mapper to extract task info
315 const mappedTask = fieldMapper.mapFromFrontmatter(yaml, path, storeTitleInFilename);
316
317 // Ensure required fields have defaults
318 const taskInfo: TaskInfo = {
319 title: mappedTask.title || "Untitled task",
320 status: mappedTask.status || defaultStatus || "open",
321 priority: mappedTask.priority || "normal",
322 due: mappedTask.due,
323 scheduled: mappedTask.scheduled,
324 path,
325 archived: mappedTask.archived || false,
326 tags: mappedTask.tags || [],
327 contexts: mappedTask.contexts || [],
328 projects: mappedTask.projects || [],
329 recurrence: mappedTask.recurrence,
330 complete_instances: mappedTask.complete_instances,
331 completedDate: mappedTask.completedDate,
332 timeEstimate: mappedTask.timeEstimate,
333 timeEntries: mappedTask.timeEntries,
334 dateCreated: mappedTask.dateCreated,
335 dateModified: mappedTask.dateModified,
336 reminders: mappedTask.reminders,
337 };
338
339 return taskInfo;
340 } else {
341 // Fallback to default field mapping
342 const defaultMapper = new FieldMapper(DEFAULT_FIELD_MAPPING);
343 const mappedTask = defaultMapper.mapFromFrontmatter(yaml, path, storeTitleInFilename);
344
345 return {
346 title: mappedTask.title || "Untitled task",
347 status: mappedTask.status || defaultStatus || "open",
348 priority: mappedTask.priority || "normal",
349 due: mappedTask.due,
350 scheduled: mappedTask.scheduled,
351 path,
352 archived: mappedTask.archived || false,
353 tags: mappedTask.tags || [],
354 contexts: mappedTask.contexts || [],
355 projects: mappedTask.projects || [],
356 recurrence: mappedTask.recurrence,

Calls 2

mapFromFrontmatterMethod · 0.95
getFileCacheMethod · 0.80

Tested by

no test coverage detected