Signed-off-by: Traxus <shyidx@gmail.com>

This commit is contained in:
Traxus 2023-04-24 17:07:17 -04:00
parent 842475198d
commit 241fec591d
2 changed files with 21 additions and 18 deletions

View File

@ -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<any> {
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<any[]> {
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<any> {
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<any> {
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<any> {
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<any> {
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<any> {
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
}

View File

@ -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<any> {
let relatedBlogPosts = {}
if (process.env.NEXT_PUBLIC_DATOCMS_BYPASS_TYPE === 'local_json') {