refactor(arch): extract TemplateEngine with single-pass registry (#211) - #217
Merged
Conversation
Replace parallel switch/case blocks in util/dates.ts with a central
TEMPLATE_VARIABLE_MAP in src/journal/template-engine.ts. Each entry
holds both a resolve fn and a momentFormat string, making it
structurally impossible for the two resolution modes to drift.
- resolveDate: thread-safe via moment(date).locale(loc), single-pass regex callback
- toMomentFormat: same registry, also fixes the ${week} → 'w' gap
- Deletes third duplicate from src/test/direct/path-parse-with-date.ts
- Updates all callers: paths.ts, conf.ts, sync-daily-links.ts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Owner
Author
Architecture Review: Final Approval (PR #217)I have performed a critical architectural review of this PR. The implementation is exceptionally clean and rigorously adheres to the mandates set during the planning phase. Key Achievements:
This refactor significantly raises the architectural standard of the project. LGTM. Note: Gemini was involved in creating this comment (but not without consulting me). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
resolveDateandtoMomentFormatintosrc/journal/template-engine.tswith a centralTEMPLATE_VARIABLE_MAPregistry — adding a new template variable now requires editing exactly one placesrc/util/dates.tsand the third duplicate fromsrc/test/direct/path-parse-with-date.ts${week}gap intoMomentFormat(was silently dropped; now maps to'w')moment(date).locale(loc)replaces globalmoment.locale()mutationregex.replace(callback)replaces multipleforEach+string.replacecallsCloses
Closes #211
Spec / Plan
Test plan
src/test/suite/template-engine.test.ts— 21 new assertions covering all 7 named variables, custom${d:fmt}, locale isolation,toMomentFormatmappings including${week}, edge casesreplace-variables-in-string.tsandpath-parse-with-date.tsdirect tests updated to import from new engine — behavior unchangednpx tsc --noEmitpasses cleannpm run compile(esbuild) passes clean🤖 Generated with Claude Code