import dotenv from 'dotenv' import config from '../nuxt.config.js' import { getAppType } from '../helpers/app-derived.js' import { makeLastUpdatedFriendly } from '../helpers/parse-date' import VideoRow from '../components-eleventy/video/row.js' // import VideoRow from '../components-eleventy/video/row.js' // import { isVideo } from '../helpers/app-derived' // Setup dotenv dotenv.config() export const makeTitle = function ( app ) { return `Does ${app.name} work on Apple Silicon? - ${ config.head.title }` } export const makeDescription = function ( app ) { return `Latest reported support status of ${ app.name } on Apple Silicon and Apple M1 Processors.` } export function renderPageLinksHtml ( links ) { return links.map( (link, i) => { const notAppTestLink = !link.label.includes('🧪') const isMainLink = (i === 0) && notAppTestLink return /* html */` ${ isMainLink ? 'View' : link.label } ` } ).join('') } export class AppTemplate { // or `async data() {` // or `get data() {` data () { return { layout: 'default.11ty.js', pagination: { data: 'eleventy-endpoints', size: 1, alias: 'app', before: function( data ) { return data.filter( entry => { const appType = getAppType( entry.payload.app ) return appType === 'app' }) } }, eleventyComputed: { title: ({ app: { payload: { app } } }) => { // console.log('data', data) return makeTitle( app ) }, description: ({ app: { payload: { app } } }) => { return makeDescription( app ) }, mainHeading: ({ app: { payload: { app } } }) => { return `Does ${ app.name } work on Apple Silicon?` }, }, permalink: ({ app }) => { // console.log('payload', app.payload) return app.route.substring(1) + '/' } } } render( data ) { const { app: { payload: { app, relatedVideos = [] } } } = data // console.log('video.payload', Object.keys(video.payload)) const lastUpdatedFriendly = makeLastUpdatedFriendly( app.lastUpdated ) const relatedLinksHtml = renderPageLinksHtml( app.relatedLinks ) return /* html */` ${ data.mainHeading } ${ app.text } ${ relatedLinksHtml } ${ relatedVideos.length > 0 ? /* html */` Related Videos ${ this.boundComponent(VideoRow)( relatedVideos ) } ` : '' } ${ lastUpdatedFriendly !== null ? /* html */` Last Updated ${ lastUpdatedFriendly } ` : '' } Report Update ` } } module.exports = AppTemplate