refactor ensure-daily-note

This commit is contained in:
Ramnique Singh 2026-04-21 11:06:09 +05:30
parent a86f555cbb
commit fbbaeea1df

View file

@ -3,13 +3,14 @@ import fs from 'fs';
import { stringify as stringifyYaml } from 'yaml'; import { stringify as stringifyYaml } from 'yaml';
import { TrackBlockSchema } from '@x/shared/dist/track-block.js'; import { TrackBlockSchema } from '@x/shared/dist/track-block.js';
import { WorkDir } from '../config/config.js'; import { WorkDir } from '../config/config.js';
import z from 'zod';
const KNOWLEDGE_DIR = path.join(WorkDir, 'knowledge'); const KNOWLEDGE_DIR = path.join(WorkDir, 'knowledge');
const DAILY_NOTE_PATH = path.join(KNOWLEDGE_DIR, 'Today.md'); const DAILY_NOTE_PATH = path.join(KNOWLEDGE_DIR, 'Today.md');
interface Section { interface Section {
heading: string; heading: string;
track: unknown; track: z.infer<typeof TrackBlockSchema>;
} }
const SECTIONS: Section[] = [ const SECTIONS: Section[] = [
@ -143,8 +144,7 @@ Do NOT invent busywork.`,
function buildDailyNoteContent(): string { function buildDailyNoteContent(): string {
const parts: string[] = ['# Today', '']; const parts: string[] = ['# Today', ''];
for (const { heading, track } of SECTIONS) { for (const { heading, track } of SECTIONS) {
const parsed = TrackBlockSchema.parse(track); const yaml = stringifyYaml(track, { lineWidth: 0, blockQuote: 'literal' }).trimEnd();
const yaml = stringifyYaml(parsed, { lineWidth: 0, blockQuote: 'literal' }).trimEnd();
parts.push( parts.push(
heading, heading,
'', '',
@ -152,8 +152,8 @@ function buildDailyNoteContent(): string {
yaml, yaml,
'```', '```',
'', '',
`<!--track-target:${parsed.trackId}-->`, `<!--track-target:${track.trackId}-->`,
`<!--/track-target:${parsed.trackId}-->`, `<!--/track-target:${track.trackId}-->`,
'', '',
); );
} }