Skip to content

Commit

Permalink
perf: Использование flatMap в sitemap-routes.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ExEr7um committed Jul 28, 2024
1 parent 05eae58 commit 20f2a17
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/runtime/api/sitemap-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ export default eventHandler(async () => {
return []
})

/** Массив всех ссылок */
const routes = Object.entries(data)
.map(([entity, slugsArray]) =>
slugsArray.map((item) => {
return { _i18nTransform: true, loc: `${entity}/${item.slug}` }
})
) // `entity` — название сущности, `slugsArray` — массив слагов
.reduce((acc, val) => acc.concat(val), []) // Объединение массивов. `acc` - аккумулятор, `val` - текущее значение

return routes
// Возвращаем массив всех ссылок
return Object.entries(data).flatMap(([entity, slugsArray]) =>
slugsArray.map((item) => {
return { _i18nTransform: true, loc: `${entity}/${item.slug}` }
})
)
})

0 comments on commit 20f2a17

Please sign in to comment.