diff --git a/server/parser/index.js b/server/parser/index.js index 3a1e448..8db1e6c 100644 --- a/server/parser/index.js +++ b/server/parser/index.js @@ -39,10 +39,24 @@ export class Parser { const dayPlans = []; for (const plan of plans) { const foundPlan = dayPlans.find((e) => e.date == plan.date); - if (!foundPlan) dayPlans.push(plan); - else { + if (!foundPlan) { + // Make sure to not insert duplicate substitutions within a file + const changes = structuredClone(plan.changes); + const cleanedChanges = []; + for (const change of changes) { + const changeExists = cleanedChanges.find( + (e) => JSON.stringify(e) == JSON.stringify(change), + ); + if (!changeExists) { + cleanedChanges.push(change); + } + // Use the new array of changes + plan.changes = cleanedChanges; + } + dayPlans.push(plan); + } else { for (const change of plan.changes) { - // Make sure to not insert the exact same substitution twice + // Make sure to not insert a substitution that already exists in the changes const changeExists = foundPlan.changes.find( (e) => JSON.stringify(e) == JSON.stringify(change), );