From 241fec591dfd324718d0f909bd2d4bef9e829a26 Mon Sep 17 00:00:00 2001 From: Traxus Date: Mon, 24 Apr 2023 17:07:17 -0400 Subject: [PATCH] Signed-off-by: Traxus --- src/lib/datocms-bypass.ts | 34 +++++++++++++++++++--------------- src/pages/blog/[slug].tsx | 5 ++--- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/lib/datocms-bypass.ts b/src/lib/datocms-bypass.ts index 61fbd76..a31bf04 100644 --- a/src/lib/datocms-bypass.ts +++ b/src/lib/datocms-bypass.ts @@ -33,7 +33,8 @@ export async function datocmsQueryIntercept(query: any) { } else if (pageQueryWhitelist.includes(parent)) { interceptData = await datocmsPageQueryIntercept(query) } else { - interceptData = {error: + interceptData = { + error: 'Unable to intercept datocms query. No viable JSON alternative was defined.' } } @@ -81,7 +82,10 @@ function getListingQueryDirectories(): string[] { function pluckFirstParentFromQuery(query: any): string { //-----only plucks the FIRST parent, if there are multiple parents in the query they will be ignored. - const parent: string = ((query.replace(/[\W_]+/g," ")).trim()).split(" ")[0] + const parent: string = ((query + .replace(/[\W_]+/g, ' ')) + .trim()) + .split(' ')[0] return parent } @@ -110,7 +114,7 @@ async function datocmsListingQueryIntercept(query: any): Promise { const parent: string = pluckFirstParentFromQuery(query) let jsonData: any = {} - switch(parent) { + switch (parent) { case 'allBlogPosts': //-----blog listing is handled in its own annoyingly special way //-----could build it out here to be verbose but will not in the intrest of time/budget @@ -323,7 +327,7 @@ function getFakePaginationData(json: any) { async function getAllBlogPostsJson() { const jsonDirectory = getBlogJsonDirectoryPath() - const validationNodes = getRequiedBlogPostNodes() + const validationNodes = getRequiedBlogPostNodes() const blogPosts = await getJsonItemsFromDirectory( jsonDirectory, pluckBlogPostData, @@ -518,7 +522,7 @@ function getRequiedBlogBlogCategoryNodes() { export async function getAllBlogCategoriesJson(): Promise { const jsonDirectory = getBlogCategoriesJsonDirectoryPath() - const validationNodes = getRequiedBlogBlogCategoryNodes() + const validationNodes = getRequiedBlogBlogCategoryNodes() const allBlogCategoriesJson: any[] = await getJsonItemsFromDirectory( jsonDirectory, pluckBlogCategoriesData, @@ -571,7 +575,7 @@ function getRequiedEventNodes() { } function sortEventsJsonByStartDate(json: any[]) { - let sortedJson: any[] = json + const sortedJson: any[] = json .slice() .sort( (a: any, b: any) => @@ -583,7 +587,7 @@ function sortEventsJsonByStartDate(json: any[]) { async function getAllEventsJson(): Promise { const jsonDirectory = getEventsJsonDirectoryPath() - const validationNodes = getRequiedEventNodes() + const validationNodes = getRequiedEventNodes() const events: any[] = await getJsonItemsFromDirectory( jsonDirectory, pluckEventData, @@ -632,7 +636,7 @@ function sortPositionsJsonById(json: any[]) { async function getAllPositionsJson(): Promise { const jsonDirectory = getPositionsJsonDirectoryPath() - const validationNodes = getRequiedPositionNodes() + const validationNodes = getRequiedPositionNodes() const positions: any[] = await getJsonItemsFromDirectory( jsonDirectory, pluckPositionData, @@ -673,7 +677,7 @@ function getRequiedPressReleaseNodes() { } function sortPressReleasesJsonByDate(json: any[]) { - let sortedJson: any[] = json + const sortedJson: any[] = json .slice() .sort( (a: any, b: any) => datocmsDateToIng(b.date) - datocmsDateToIng(a.date) @@ -684,7 +688,7 @@ function sortPressReleasesJsonByDate(json: any[]) { async function getAllPressReleasesJson(): Promise { const jsonDirectory = getPressReleasesJsonDirectoryPath() - const validationNodes = getRequiedPressReleaseNodes() + const validationNodes = getRequiedPressReleaseNodes() const pressReleases: any[] = await getJsonItemsFromDirectory( jsonDirectory, pluckPressReleaseData, @@ -732,14 +736,14 @@ function sortTeamsJsonById(json: any[]) { async function getAllTeamsJson(): Promise { const jsonDirectory = getTeamsJsonDirectoryPath() - const validationNodes = getRequiedTeamNodes() + const validationNodes = getRequiedTeamNodes() const teams: any[] = await getJsonItemsFromDirectory( jsonDirectory, pluckTeamData, validationNodes ) - let sortedTeams: any[] = sortTeamsJsonById(teams) - let allTeamsJson = { allTeams: sortedTeams } + const sortedTeams: any[] = sortTeamsJsonById(teams) + const allTeamsJson = { allTeams: sortedTeams } return allTeamsJson } @@ -782,14 +786,14 @@ function sortTestimonialsJsonById(json: any[]) { async function getAllTestimonialsJson(): Promise { const jsonDirectory = getTestimonialsJsonDirectoryPath() - const validationNodes = getRequiedTestimonialNodes() + const validationNodes = getRequiedTestimonialNodes() const testimonials: any[] = await getJsonItemsFromDirectory( jsonDirectory, pluckTestimonialData, validationNodes ) const sortedTestimonals: any[] = sortTestimonialsJsonById(testimonials) - const allTestimonialsJson = {allTestimonials: sortedTestimonals} + const allTestimonialsJson = { allTestimonials: sortedTestimonals } return allTestimonialsJson } \ No newline at end of file diff --git a/src/pages/blog/[slug].tsx b/src/pages/blog/[slug].tsx index 62c9b62..1ddef6c 100644 --- a/src/pages/blog/[slug].tsx +++ b/src/pages/blog/[slug].tsx @@ -72,7 +72,7 @@ export const getStaticPaths: GetStaticPaths = async () => { } else { postsSlugsJson = await getAllBlogPostsSlugs() } - + return postsSlugsJson } @@ -114,11 +114,10 @@ export const getStaticProps: GetStaticProps = async ( p.category.some((c) => post?.category.some((postCategory) => c.slug === postCategory.slug) ) - ) + ) */ async function getRelatedBlogPostsFromSource(): Promise { - let relatedBlogPosts = {} if (process.env.NEXT_PUBLIC_DATOCMS_BYPASS_TYPE === 'local_json') {