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

This commit is contained in:
Traxus 2023-04-24 17:15:32 -04:00
parent 241fec591d
commit 92cd414663
3 changed files with 16 additions and 19 deletions

View File

@ -35,7 +35,7 @@ export async function datocmsQueryIntercept(query: any) {
} else {
interceptData = {
error:
'Unable to intercept datocms query. No viable JSON alternative was defined.'
'Unable to intercept datocms query. No viable JSON alternative was defined.'
}
}
@ -82,9 +82,9 @@ 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())
const parent: string = query
.replace(/[\W_]+/g, ' ')
.trim()
.split(' ')[0]
return parent
}
@ -372,9 +372,7 @@ export async function getAllBlogPostsFromSource(
return allBlogPostsFromSource
}
async function getSingleBlogPostJsonBySlug(
slug: string
): Promise<any> {
async function getSingleBlogPostJsonBySlug(slug: string): Promise<any> {
const jsonDirectory = getBlogJsonDirectoryPath()
const jsonFile = slug + '.json'
const jsonPath = path.join(jsonDirectory, jsonFile)
@ -402,7 +400,7 @@ export async function getSingleBlogPostBySlugFromSource(
if (process.env.NEXT_PUBLIC_DATOCMS_BYPASS_TYPE === 'local_json') {
try {
blogPostJson = await getSingleBlogPostJsonBySlug(slug)
blogPostJson = await getSingleBlogPostJsonBySlug(slug)
} catch (e) {
//console.log('Failed pull blog post with slug ' + slug)
//console.log('The attempt resulted in the following error:')
@ -415,9 +413,7 @@ export async function getSingleBlogPostBySlugFromSource(
return blogPostJson
}
function getBlogPostCategorySlugs(
blogPostJson: any
) {
function getBlogPostCategorySlugs(blogPostJson: any) {
const categories = []
try {
@ -470,9 +466,9 @@ export async function getRelatedBlogPosts(
matchedCount++
break
}
}
}
}
}
}
}
if (matchedCount < matchCount) {
@ -578,7 +574,7 @@ function sortEventsJsonByStartDate(json: any[]) {
const sortedJson: any[] = json
.slice()
.sort(
(a: any, b: any) =>
(a: any, b: any) =>
datocmsDateToIng(b.eventStartdate) - datocmsDateToIng(a.eventStartdate)
)
@ -629,7 +625,7 @@ function getRequiedPositionNodes() {
function sortPositionsJsonById(json: any[]) {
const sortedJson: any[] = json
.slice()
.sort((a: any, b: any) => parseInt(a.id) - parseInt(b.id))
.sort((a: any, b: any) => parseInt(a.id) - parseInt(b.id))
return sortedJson
}
@ -796,4 +792,4 @@ async function getAllTestimonialsJson(): Promise<any> {
const allTestimonialsJson = { allTestimonials: sortedTestimonals }
return allTestimonialsJson
}
}

View File

@ -136,7 +136,8 @@ export const getStaticProps: GetStaticProps = async (
const relatedPosts = allBlogPosts.data.filter((p) =>
p.category.some((c) =>
post?.category.some((postCategory: any) => c.slug === postCategory.slug)
post?.category.some(
(postCategory: any) => c.slug === postCategory.slug)
)
)

View File

@ -114,7 +114,8 @@ const BlogIndexPage = ({
pages: [initialBlogPosts]
}
: undefined,
getNextPageParam: (lastPage) => lastPage.pagination.nextPage ?? undefined
getNextPageParam: (lastPage) =>
lastPage.pagination.nextPage ?? undefined
}
)
@ -240,7 +241,6 @@ export const getStaticProps = async () => {
//===== \/ START NEXT_PUBLIC_DATOCMS_BYPASS \/ ====================================================
function getInitialBlogPostsDataProp(allBlogPosts: any) {
let initialBlogPostsDataProp: any[] = []
if (process.env.NEXT_PUBLIC_DATOCMS_BYPASS_TYPE === 'local_json') {