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
| File | Description |
|---|
src/lib/date.ts | Centralized date-fns utility library with formatting, parsing, navigation, and calculation functions |
Components Updated
| File | Status | Changes |
|---|
src/components/navigation/benben/Header.astro | ✅ Updated | Replaced format, parse, subMonths, addMonths with formatMonthYear, formatYearMonthPath, parseDateFromPath, getPrevMonth, getNextMonth |
src/components/navigation/hygge/Header.astro | ✅ Updated | Replaced format, parse, subMonths, addMonths with formatMonthYear, formatYearMonthPath, parseDateFromPath, getPrevMonth, getNextMonth |
src/components/planner/benben/create/NewGoal.astro | ✅ Updated | Replaced complex due date calculation logic with calculateWeekDueDate |
src/components/react/migrated/Calendar.tsx | ✅ Updated | Replaced multiple date-fns imports with library functions for formatting, parsing, and calendar operations |
src/components/react/migrated/Week.tsx | ✅ Updated | Replaced date-fns imports with library functions for week display and weekend detection |
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
Navigation Functions
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
- Code Reusability: Common date operations are now centralized
- Consistency: All components use the same date formatting patterns
- Maintainability: Changes to date logic only need to be made in one place
- Reduced Bundle Size: Components import only what they need
- 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
| File | Function | Description |
|---|
src/lib/yearly.ts | ideas(project, year, styles?) | Fetch all ideas for a specific project within a given year |
src/lib/yearly.ts | currentMonthIdeas(project, year, month, styles?) | Fetch ideas for the current month |
src/lib/yearly.ts | previousMonthsIdeas(project, year, month, styles?) | Fetch ideas from previous months of the current year |
Pages Updated
| File | Status | Changes |
|---|
src/pages/benben/ideas/index.astro | ✅ Updated | Changed from @/lib/monthly to @/lib/yearly for fetching bearlabs and walkingweekend ideas |
src/pages/benben/ideas/benben/index.astro | ✅ Updated | Changed from monthly to yearly ideas fetch for reading and speaking projects |
src/pages/benben/ideas/hygge/index.astro | ✅ Updated | Changed from monthly to yearly ideas fetch for thinking project |
src/pages/benben/ideas/bearlabs/index.astro | ✅ Updated | Uses currentMonthIdeas and previousMonthsIdeas from yearly.ts (replaces @/lib/previous) |
src/pages/benben/ideas/walkingweekend/index.astro | ✅ Updated | Uses currentMonthIdeas and previousMonthsIdeas from yearly.ts (replaces @/lib/previous) |
src/pages/2026/01/benben/ideas/index.astro | ✅ Updated | Changed from @/lib/monthly to @/lib/yearly for fetching bearlabs and walkingweekend ideas |
src/pages/2026/01/benben/ideas/benben/index.astro | ✅ Updated | Changed from monthly to yearly ideas fetch for reading and speaking projects |
src/pages/2026/01/benben/ideas/hygge/index.astro | ✅ Updated | Changed from monthly to yearly ideas fetch for thinking project |
src/pages/2026/01/benben/ideas/bearlabs/index.astro | ✅ Updated | Uses currentMonthIdeas and previousMonthsIdeas from yearly.ts (replaces @/lib/previous) |
src/pages/2026/01/benben/ideas/walkingweekend/index.astro | ✅ Updated | Uses currentMonthIdeas and previousMonthsIdeas from yearly.ts (replaces @/lib/previous) |
Before vs After
| Behavior | Before | After |
|---|
| Ideas shown | All ideas from all years | Only ideas from current year |
| Data source | monthly.ts + previous.ts | yearly.ts only |
| Ideas section | Current month ideas | Current month ideas (same) |
| Thoughts section | All-time historical ideas | Previous months of current year only |
Benefits
- Yearly Scope: Ideas are now scoped to the current year instead of all-time
- Better Performance: Fetching only current year data reduces query size
- Focused Content: Users see only relevant current-year ideas
- Maintains Separation: Current month and previous months ideas still displayed in separate sections
- Simpler Logic: Removed dependency on
@/lib/previous for ideabox pages