Make eleventy js templates asynchronus

This commit is contained in:
Sam Carlton 2021-05-08 15:31:01 -05:00
parent bb40fd294c
commit 84355645bf
4 changed files with 16 additions and 10 deletions

View file

@ -9,14 +9,14 @@ function pill ( text ) {
`
}
export default function ( video, options = {} ) {
export default async function ( video, options = {} ) {
const {
width = '325px',
classes = 'w-full flex-shrink-0 flex-grow-0 border-2 border-transparent rounded-2xl overflow-hidden'
} = options
// Setup inline lazysizes
this.usingComponent( 'node_modules/lazysizes/lazysizes.min.js' )
await this.usingComponent( 'node_modules/lazysizes/lazysizes.min.js' )
// console.log('video', video)

View file

@ -10,7 +10,7 @@ function getCardType ( video ) {
return VideoCard
}
export default function ( videos, options = {} ) {
export default async function ( videos, options = {} ) {
const {
cardWidth = '325',
@ -24,17 +24,19 @@ export default function ( videos, options = {} ) {
const rowId = `row-${ uid }`
// Setup inline lazysizes
this.usingComponent( 'helpers/scroll.js' )
await this.usingComponent( 'helpers/scroll.js' )
// console.log('video', video)
const cardsHtml = videos.map( video => {
const renderedCards = await Promise.all(videos.map( async video => {
const Card = getCardType( video )
// console.log('Card', this.boundComponent(Card)( video ) )
return this.boundComponent(Card)( video )
} ).join('')
return await this.boundComponent(Card)( video )
} ))
const cardsHtml = renderedCards.join('')
// console.log( 'cardsHtml', cardsHtml )