From 2a6174e955bb0afd1b1703a03f4c18ce392b7db2 Mon Sep 17 00:00:00 2001 From: Traxus Date: Fri, 21 Apr 2023 20:11:27 -0400 Subject: [PATCH] Signed-off-by: Traxus --- src/lib/datocms-bypass.ts | 42 ++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/lib/datocms-bypass.ts b/src/lib/datocms-bypass.ts index bc13908..540079a 100644 --- a/src/lib/datocms-bypass.ts +++ b/src/lib/datocms-bypass.ts @@ -27,10 +27,10 @@ function datocmsDateToIng(date : string) : number { export async function datocmsQueryIntercept(query : any) : Promise { let parent = pluckFirstParentFromQuery(query); let pageQueryWhitelist = getPageQueryBypassWhitelist(); - let listingDirectory = getListingDirectoryByQueryParent(parent); + let listingQueryWhitelist = getListingQueryDirectories(); let interceptData = {}; - if (listingDirectory) { + if (listingDirectory.includes(parent)) { interceptData = await datocmsListingQueryIntercept(query); } else if (pageQueryWhitelist.includes(parent)) { interceptData = await datocmsPageQueryIntercept(query); @@ -42,6 +42,30 @@ export async function datocmsQueryIntercept(query : any) : Promise { return interceptData; } +function getPageQueryBypassWhitelist() : string[] { + //-----stuff that has been (to the best of my knowledge) completley pulled over into JSON + //-----does not include iterative stuff like blog posts or events etc... + //-----this may only end up being scaffolding. + + let whitelist : string [] = []; + + whitelist.push('aboutPage'); + whitelist.push('careersPage'); + whitelist.push('communityPage'); + whitelist.push('contactPage'); + whitelist.push('homePage'); + whitelist.push('partnersPage'); + whitelist.push('pressPage'); + whitelist.push('privacyPage'); + whitelist.push('productsPage'); + whitelist.push('termsPage'); + + whitelist.push('header'); + whitelist.push('footer'); + + return whitelist; +} + function getListingQueryDirectories() : string[] { //-----whitelist the listying types of content... @@ -57,20 +81,6 @@ function getListingQueryDirectories() : string[] { } -function getListingDirectoryByQueryParent(parent : string) : string { - //-----this acts as a whitelist and a mapping to the folder name... - - let directories : any[] = getListingQueryDirectories(); - let directory : string = ''; - - if (directories.includes(parent)) { - directory = directories[parent]; - } - - return directory; - -} - function pluckFirstParentFromQuery(query : any) : string { //-----only plucks the FIRST parent, if there are multiple parents in the query they will be ignored.