Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Чинит промо под новую версию 11ty #1229

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions src/views/index.11tydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,48 @@ const defaultPromo = {
title: 'Друг для друга',
}

const asyncFilter = async (arr, predicate) => {
const results = await Promise.all(arr.map(predicate))
return arr.filter((_v, index) => results[index])
}

module.exports = {
layout: 'base.njk',
permalink: '/',
documentTitle: 'Дока',
documentDescription: 'Документация для разработчиков на понятном языке',

eleventyComputed: {
promoData: function (data) {
promoData: async function (data) {
const { collections } = data
const { promos } = collections

const promo = promos
.filter((p) => {
const currentDate = new Date()
return currentDate >= new Date(p.data.startDate) && currentDate <= new Date(p.data.endDate)
})
.map((p) => {
const filteredPromos = await asyncFilter(promos, async (promo) => {
const currentDate = new Date()
const cache = await promo.template._frontMatterDataCache
return currentDate >= new Date(cache.startDate) && currentDate <= new Date(cache.endDate)
})

const formattedPromos = await Promise.all(
filteredPromos.map(async (promo) => {
const content = await promo.template.inputContent
const cache = await promo.template._frontMatterDataCache
const output = {
color: p.data.color,
content: p.template.inputContent
color: cache.color,
content: content
.split('---')[2]
.split('\n')
.filter((s) => s !== '')
.join('\n'),
design: p.data.design,
links: p.data.links,
title: p.data.title,
design: cache.design,
links: cache.links,
title: cache.title,
}
return output
})[0]
}),
)

return promo || defaultPromo
return formattedPromos[0] || defaultPromo
},
},
}
Loading