Filter eleventy endpoints by route, not payload

This commit is contained in:
Sam Carlton 2021-05-08 16:48:08 -05:00
parent 44fa023a06
commit 37a296adfe
4 changed files with 16 additions and 16 deletions

View file

@ -56,4 +56,10 @@ export function getVideoEndpoint ( video ) {
return `/tv/${video.slug}`
}
export function getRouteType ( routeString ) {
// Remove first slash and split by remaining
// slashes to get first part of route
const [ routeType ] = routeString.substring(1).split('/')
return routeType
}

View file

@ -2,7 +2,7 @@ import dotenv from 'dotenv'
import config from '../nuxt.config.js'
import { getAppType } from '../helpers/app-derived.js'
import { getAppType, getRouteType } from '../helpers/app-derived.js'
import { deviceSupportsApp } from '../helpers/devices.js'
import { makeLastUpdatedFriendly } from '../helpers/parse-date'
@ -56,12 +56,10 @@ export class AppTemplate {
before: function( data ) {
return data.filter( entry => {
// Skip endpoints with no payload
if ( entry === undefined || !entry.hasOwnProperty('payload') ) return false
// const [ _, routeType ] = entry.route.split('/')
const routeType = getRouteType( entry.route )
const appType = getAppType( entry.payload.app )
return appType === 'app'
return routeType === 'app'
})
}
},

View file

@ -2,7 +2,7 @@ import dotenv from 'dotenv'
import config from '../nuxt.config.js'
import { getAppType } from '../helpers/app-derived.js'
import { getAppType, getRouteType } from '../helpers/app-derived.js'
import { AppTemplate } from './app.11ty.js'
@ -33,12 +33,9 @@ class FormulaTemplate extends AppTemplate {
alias: 'app',
before: function( data ) {
return data.filter( entry => {
// Skip endpoints with no payload
if ( entry === undefined || !entry.hasOwnProperty('payload') ) return false
const routeType = getRouteType( entry.route )
const appType = getAppType( entry.payload.app )
return appType === 'formula'
return routeType === 'formula'
})
}
},

View file

@ -3,7 +3,7 @@ import dotenv from 'dotenv'
import config from '../nuxt.config'
import VideoRow from '../components-eleventy/video/row.js'
import { isVideo } from '../helpers/app-derived'
import { isVideo, getRouteType } from '../helpers/app-derived'
// Setup dotenv
dotenv.config()
@ -35,10 +35,9 @@ class TV {
alias: 'payload',
before: function( data ) {
return data.filter( entry => {
// Skip endpoints with no payload
if ( entry === undefined || !entry.hasOwnProperty('payload') ) return false
const routeType = getRouteType( entry.route )
return entry.payload.hasOwnProperty('video') && isVideo( entry.payload.video )
return routeType === 'tv'
})
}
},