Refactoring & Improvements

Summary

Extracted common date-fns related functions from components and consolidated them into a centralized utility library at src/lib/date.ts.

New Library Created

FileDescription
src/lib/date.tsCentralized date-fns utility library with formatting, parsing, navigation, and calculation functions

Components Updated

FileStatusChanges
src/components/navigation/benben/Header.astro✅ UpdatedReplaced format, parse, subMonths, addMonths with formatMonthYear, formatYearMonthPath, parseDateFromPath, getPrevMonth, getNextMonth
src/components/navigation/hygge/Header.astro✅ UpdatedReplaced format, parse, subMonths, addMonths with formatMonthYear, formatYearMonthPath, parseDateFromPath, getPrevMonth, getNextMonth
src/components/planner/benben/create/NewGoal.astro✅ UpdatedReplaced complex due date calculation logic with calculateWeekDueDate
src/components/react/migrated/Calendar.tsx✅ UpdatedReplaced multiple date-fns imports with library functions for formatting, parsing, and calendar operations
src/components/react/migrated/Week.tsx✅ UpdatedReplaced date-fns imports with library functions for week display and weekend detection

Functions Extracted

Formatting Functions

  • formatMonthYear(date) → “MMMM yyyy”
  • formatYearMonthPath(date) → “/yyyy/MM”
  • formatYearMonthDay(date) → “yyyy-MM-dd”
  • formatMonthShort(date) → “MMM, yyyy”
  • formatDate(date, pattern) → custom pattern
  • formatDay(date) → day number
  • formatDayOfWeek(date) → 1-7 (Monday-Sunday)

Parsing Functions

  • parseDateFromPath(path) → parses “/yyyy/MM”
  • parseDateString(dateStr) → parses “yyyy-MM-dd”
  • parseWeekNumber(weekNum, year) → date from week number
  • parseDate(dateStr, pattern) → custom pattern
  • getPrevMonth(date) / getNextMonth(date)
  • getPrevMonthPath(date) / getNextMonthPath(date)

Week Utilities

  • getWeekNumber(date) → ISO week number
  • getWeeksInMonthCount(date) → weeks in a month
  • getMonthStartWeek(date) → week number at month start
  • getSundayOfWeek(weekNo, year) → Sunday of given week
  • getDaysInWeek(date) / getDaysInMonth(date)
  • getLastWeekOfYear(year) → last week number

Due Date Calculation

  • calculateWeekDueDate(weekNo, year) → due date for weekly goals

Day Checks

  • checkIsToday(date)
  • isWeekend(date) → Friday, Saturday, or Sunday
  • checkIsFriday(date), checkIsSaturday(date), checkIsSunday(date)

Reference Dates

  • getToday(), getTodayString()
  • getMonthStart(date), getMonthEnd(date)
  • getWeekStart(date), getWeekEnd(date)

Benefits

  1. Code Reusability: Common date operations are now centralized
  2. Consistency: All components use the same date formatting patterns
  3. Maintainability: Changes to date logic only need to be made in one place
  4. Reduced Bundle Size: Components import only what they need
  5. Type Safety: All functions are properly typed with TypeScript

Ideabox Yearly Filtering

Summary

Updated the Ideabox pages to only show ideas from the current year instead of all historical ideas from all years. Maintains separate sections for current month ideas and previous months’ ideas (within the same year).

New Functions Added

FileFunctionDescription
src/lib/yearly.tsideas(project, year, styles?)Fetch all ideas for a specific project within a given year
src/lib/yearly.tscurrentMonthIdeas(project, year, month, styles?)Fetch ideas for the current month
src/lib/yearly.tspreviousMonthsIdeas(project, year, month, styles?)Fetch ideas from previous months of the current year

Pages Updated

FileStatusChanges
src/pages/benben/ideas/index.astro✅ UpdatedChanged from @/lib/monthly to @/lib/yearly for fetching bearlabs and walkingweekend ideas
src/pages/benben/ideas/benben/index.astro✅ UpdatedChanged from monthly to yearly ideas fetch for reading and speaking projects
src/pages/benben/ideas/hygge/index.astro✅ UpdatedChanged from monthly to yearly ideas fetch for thinking project
src/pages/benben/ideas/bearlabs/index.astro✅ UpdatedUses currentMonthIdeas and previousMonthsIdeas from yearly.ts (replaces @/lib/previous)
src/pages/benben/ideas/walkingweekend/index.astro✅ UpdatedUses currentMonthIdeas and previousMonthsIdeas from yearly.ts (replaces @/lib/previous)
src/pages/2026/01/benben/ideas/index.astro✅ UpdatedChanged from @/lib/monthly to @/lib/yearly for fetching bearlabs and walkingweekend ideas
src/pages/2026/01/benben/ideas/benben/index.astro✅ UpdatedChanged from monthly to yearly ideas fetch for reading and speaking projects
src/pages/2026/01/benben/ideas/hygge/index.astro✅ UpdatedChanged from monthly to yearly ideas fetch for thinking project
src/pages/2026/01/benben/ideas/bearlabs/index.astro✅ UpdatedUses currentMonthIdeas and previousMonthsIdeas from yearly.ts (replaces @/lib/previous)
src/pages/2026/01/benben/ideas/walkingweekend/index.astro✅ UpdatedUses currentMonthIdeas and previousMonthsIdeas from yearly.ts (replaces @/lib/previous)

Before vs After

BehaviorBeforeAfter
Ideas shownAll ideas from all yearsOnly ideas from current year
Data sourcemonthly.ts + previous.tsyearly.ts only
Ideas sectionCurrent month ideasCurrent month ideas (same)
Thoughts sectionAll-time historical ideasPrevious months of current year only

Benefits

  1. Yearly Scope: Ideas are now scoped to the current year instead of all-time
  2. Better Performance: Fetching only current year data reduces query size
  3. Focused Content: Users see only relevant current-year ideas
  4. Maintains Separation: Current month and previous months ideas still displayed in separate sections
  5. Simpler Logic: Removed dependency on @/lib/previous for ideabox pages