mirror of
https://github.com/LaconicNetwork/laconic.com.git
synced 2026-05-09 04:04:06 +00:00
Signed-off-by: Traxus <shyidx@gmail.com>
This commit is contained in:
parent
03b1696d8a
commit
3126bb539e
@ -33,7 +33,9 @@ export async function datocmsQueryIntercept(query: any) {
|
||||
} else if (pageQueryWhitelist.includes(parent)) {
|
||||
interceptData = await datocmsPageQueryIntercept(query)
|
||||
} else {
|
||||
interceptData = {error: 'Unable to intercept datocms query. No viable JSON alternative was defined.'}
|
||||
interceptData = {error:
|
||||
'Unable to intercept datocms query. No viable JSON alternative was defined.'
|
||||
}
|
||||
}
|
||||
|
||||
return interceptData
|
||||
@ -43,8 +45,8 @@ 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 [] = []
|
||||
|
||||
const whitelist: string[] = []
|
||||
|
||||
whitelist.push('aboutPage')
|
||||
whitelist.push('careersPage')
|
||||
@ -66,7 +68,7 @@ function getPageQueryBypassWhitelist(): string[] {
|
||||
function getListingQueryDirectories(): string[] {
|
||||
//-----whitelist the listying types of content...
|
||||
|
||||
let directories: string[] = []
|
||||
const directories: string[] = []
|
||||
|
||||
directories.push('allEvents')
|
||||
directories.push('allPositions')
|
||||
@ -79,15 +81,15 @@ 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.
|
||||
let parent: string = ((query.replace(/[\W_]+/g," ")).trim()).split(" ")[0]
|
||||
const parent: string = ((query.replace(/[\W_]+/g," ")).trim()).split(" ")[0]
|
||||
return parent
|
||||
}
|
||||
|
||||
async function datocmsPageQueryIntercept(query: any): Promise<any> {
|
||||
let parent: string = pluckFirstParentFromQuery(query)
|
||||
let jsonDirectory: string = path.join(process.cwd(), 'json/site_content')
|
||||
let jsonPath: string = jsonDirectory + '/' + parent + '.json'
|
||||
let fileRawContents: string = ''
|
||||
const parent: string = pluckFirstParentFromQuery(query)
|
||||
const jsonDirectory: string = path.join(process.cwd(), 'json/site_content')
|
||||
const jsonPath: string = jsonDirectory + '/' + parent + '.json'
|
||||
let fileRawContents = ''
|
||||
let fileJson: any = {}
|
||||
let jsonData: any = {}
|
||||
|
||||
@ -96,33 +98,33 @@ async function datocmsPageQueryIntercept(query: any): Promise<any> {
|
||||
fileJson = JSON.parse(fileRawContents)
|
||||
jsonData = fileJson.data
|
||||
} catch (e) {
|
||||
console.log('Failed to parse JSON for file ' + jsonPath)
|
||||
console.log('JSON parse attempt resulted in the following error:')
|
||||
console.log(e)
|
||||
//console.log('Failed to parse JSON for file ' + jsonPath)
|
||||
//console.log('JSON parse attempt resulted in the following error:')
|
||||
//console.log(e)
|
||||
}
|
||||
|
||||
return jsonData
|
||||
return jsonData
|
||||
}
|
||||
|
||||
async function datocmsListingQueryIntercept(query: any): Promise<any> {
|
||||
let parent: string = pluckFirstParentFromQuery(query)
|
||||
const parent: string = pluckFirstParentFromQuery(query)
|
||||
let jsonData: any = {}
|
||||
|
||||
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
|
||||
//-----could build it out here to be verbose but will not in the intrest of time/budget
|
||||
//-----might need to add/remove some parent nodes in the JSON returned from getAllBlogPostsJson() to match the would-be expected format.
|
||||
//jsonData = await getAllBlogPostsJson()
|
||||
jsonData = {}
|
||||
break
|
||||
break
|
||||
case 'allCategories':
|
||||
//-----category 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
|
||||
//-----might need to add/remove some parent nodes in the JSON returned from getAllBlogCategoriesJson() to match the would-be expected format.
|
||||
//-----could build it out here to be verbose but will not in the intrest of time/budget
|
||||
//-----might need to add/remove some parent nodes in the JSON returned from getAllBlogCategoriesJson() to match the would-be expected format.
|
||||
//jsonData = await getAllBlogCategoriesJson()
|
||||
jsonData = {}
|
||||
break
|
||||
break
|
||||
case 'allEvents':
|
||||
jsonData = await getAllEventsJson()
|
||||
break
|
||||
@ -143,16 +145,16 @@ async function datocmsListingQueryIntercept(query: any): Promise<any> {
|
||||
break
|
||||
}
|
||||
|
||||
return jsonData
|
||||
return jsonData
|
||||
}
|
||||
|
||||
//-----json traversal
|
||||
function jsonFilePathIsValid(filePath: string) {
|
||||
if (filePath.startsWith("_")) {
|
||||
if (filePath.startsWith('_')) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (!filePath.endsWith(".json")) {
|
||||
if (!filePath.endsWith('.json')) {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -160,11 +162,11 @@ function jsonFilePathIsValid(filePath: string) {
|
||||
}
|
||||
|
||||
function jsonNodeExists(jsonData: any, node: string) {
|
||||
if (node in jsonData === true) {
|
||||
return true
|
||||
}
|
||||
if (node in jsonData === true) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return false
|
||||
}
|
||||
|
||||
function jsonNodesExist(jsonData: any, nodes: any) {
|
||||
@ -187,10 +189,10 @@ function jsonNodesExist(jsonData: any, nodes: any) {
|
||||
nodeGroup = node
|
||||
nodeGroupValid = false
|
||||
for (let j = 0; j < nodeGroup.length; j++) {
|
||||
nodeGroupNode = nodeGroup[j]
|
||||
nodeGroupNode = nodeGroup[j]
|
||||
if (jsonNodeExists(jsonData, nodeGroupNode) === true) {
|
||||
nodeGroupValid = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nodeGroupValid === false) {
|
||||
//-----none of the nodes in the group exist.
|
||||
@ -205,15 +207,19 @@ function jsonNodesExist(jsonData: any, nodes: any) {
|
||||
return true
|
||||
}
|
||||
|
||||
export async function getJsonItemsFromDirectory(jsonDirectory: string, pluckerFunction: any, validationNodes: any[]): Promise<any> {
|
||||
let jsonFiles = await fs.readdir(jsonDirectory)
|
||||
let returnJson: any[] = []
|
||||
export async function getJsonItemsFromDirectory(
|
||||
jsonDirectory: string,
|
||||
pluckerFunction: any,
|
||||
validationNodes: any[]
|
||||
): Promise<any> {
|
||||
const jsonFiles = await fs.readdir(jsonDirectory)
|
||||
const returnJson: any[] = []
|
||||
|
||||
for (let i = 0; i < jsonFiles.length; i++) {
|
||||
let jsonFile = jsonFiles[i]
|
||||
const jsonFile = jsonFiles[i]
|
||||
if (jsonFilePathIsValid(jsonFile) === true) {
|
||||
let jsonPath = path.join(jsonDirectory, jsonFile)
|
||||
let fileRawContents = await fs.readFile(jsonPath, 'utf8')
|
||||
const jsonPath = path.join(jsonDirectory, jsonFile)
|
||||
const fileRawContents = await fs.readFile(jsonPath, 'utf8')
|
||||
let fileJsonContents = {}
|
||||
let jsonParseSuccess = false
|
||||
|
||||
@ -222,14 +228,14 @@ export async function getJsonItemsFromDirectory(jsonDirectory: string, pluckerFu
|
||||
jsonParseSuccess = true
|
||||
} catch (e) {
|
||||
jsonParseSuccess = false
|
||||
console.log('Failed to parse JSON for file ' + jsonPath)
|
||||
console.log('JSON parse attempt resulted in the following error:')
|
||||
console.log(e)
|
||||
//console.log('Failed to parse JSON for file ' + jsonPath)
|
||||
//console.log('JSON parse attempt resulted in the following error:')
|
||||
//console.log(e)
|
||||
}
|
||||
|
||||
if (jsonParseSuccess === true) {
|
||||
fileJsonContents = JSON.parse(fileRawContents)
|
||||
let jsonData = pluckerFunction(fileJsonContents)
|
||||
const jsonData = pluckerFunction(fileJsonContents)
|
||||
jsonData.sourceFile = jsonFile
|
||||
|
||||
if (jsonNodesExist(jsonData, validationNodes) === true) {
|
||||
@ -251,8 +257,8 @@ function pluckBlogPostData(json: any) {
|
||||
//let plucked: BlogPostRecord = {}
|
||||
let plucked: any = {}
|
||||
|
||||
if('data' in json){
|
||||
if('blogPost' in json.data) {
|
||||
if ('data' in json) {
|
||||
if ('blogPost' in json.data) {
|
||||
plucked = json.data.blogPost
|
||||
}
|
||||
}
|
||||
@ -261,8 +267,8 @@ function pluckBlogPostData(json: any) {
|
||||
}
|
||||
|
||||
function getRequiedBlogPostNodes(): any[] {
|
||||
let nodes = []
|
||||
let contentNodes = []
|
||||
const nodes = []
|
||||
const contentNodes = []
|
||||
|
||||
contentNodes.push('content')
|
||||
contentNodes.push('htmlContent')
|
||||
@ -279,12 +285,12 @@ function getRequiedBlogPostNodes(): any[] {
|
||||
function forceBlogPostsJsonSlugIntegrity(json: any[]) {
|
||||
//-----this is used to force the blog post slug to match that of its parent file name.
|
||||
|
||||
let returnJson: any[] = []
|
||||
const returnJson: any[] = []
|
||||
|
||||
for (let i = 0; i < json.length; i++) {
|
||||
let blogPost = json[i]
|
||||
let sourceFile = blogPost.sourceFile
|
||||
let newSlug = path.parse(sourceFile).name
|
||||
const blogPost = json[i]
|
||||
const sourceFile = blogPost.sourceFile
|
||||
const newSlug = path.parse(sourceFile).name
|
||||
blogPost.slug = newSlug
|
||||
returnJson.push(blogPost)
|
||||
}
|
||||
@ -293,14 +299,18 @@ function forceBlogPostsJsonSlugIntegrity(json: any[]) {
|
||||
}
|
||||
|
||||
function sortBlogPostsJsonByDate(json: any[]) {
|
||||
let sortedJson: any[] = json.slice().sort((a: any, b: any) => datocmsDateToIng(b.date) - datocmsDateToIng(a.date))
|
||||
const sortedJson: any[] = json
|
||||
.slice()
|
||||
.sort(
|
||||
(a: any, b: any) => datocmsDateToIng(b.date) - datocmsDateToIng(a.date)
|
||||
)
|
||||
|
||||
return sortedJson
|
||||
}
|
||||
|
||||
function getFakePaginationData(json: any) {
|
||||
let pagination: any = {}
|
||||
let totalPosts = json.length
|
||||
const pagination: any = {}
|
||||
const totalPosts = json.length
|
||||
|
||||
pagination.nextPage = null
|
||||
pagination.page = 1
|
||||
@ -312,35 +322,41 @@ function getFakePaginationData(json: any) {
|
||||
}
|
||||
|
||||
async function getAllBlogPostsJson() {
|
||||
let jsonDirectory = getBlogJsonDirectoryPath()
|
||||
let validationNodes = getRequiedBlogPostNodes()
|
||||
let blogPosts = await getJsonItemsFromDirectory(jsonDirectory, pluckBlogPostData, validationNodes)
|
||||
let pagination = getFakePaginationData(blogPosts)
|
||||
let processedBlogPosts = forceBlogPostsJsonSlugIntegrity(blogPosts)
|
||||
let sortedBlogPosts: any[] = sortBlogPostsJsonByDate(processedBlogPosts)
|
||||
let allBlogPostsJson = {pagination: pagination, data: sortedBlogPosts}
|
||||
const jsonDirectory = getBlogJsonDirectoryPath()
|
||||
const validationNodes = getRequiedBlogPostNodes()
|
||||
const blogPosts = await getJsonItemsFromDirectory(
|
||||
jsonDirectory,
|
||||
pluckBlogPostData,
|
||||
validationNodes
|
||||
)
|
||||
const pagination = getFakePaginationData(blogPosts)
|
||||
const processedBlogPosts = forceBlogPostsJsonSlugIntegrity(blogPosts)
|
||||
const sortedBlogPosts: any[] = sortBlogPostsJsonByDate(processedBlogPosts)
|
||||
const allBlogPostsJson = { pagination: pagination, data: sortedBlogPosts }
|
||||
|
||||
return allBlogPostsJson
|
||||
}
|
||||
|
||||
export async function getAllBlogPostsSlugsFromSource() {
|
||||
let jsonDirectory = getBlogJsonDirectoryPath()
|
||||
let jsonFiles = await fs.readdir(jsonDirectory)
|
||||
let slugs = []
|
||||
const jsonDirectory = getBlogJsonDirectoryPath()
|
||||
const jsonFiles = await fs.readdir(jsonDirectory)
|
||||
const slugs = []
|
||||
|
||||
for (let i = 0; i < jsonFiles.length; i++) {
|
||||
let jsonFile = jsonFiles[i]
|
||||
const jsonFile = jsonFiles[i]
|
||||
if (jsonFilePathIsValid(jsonFile) === true) {
|
||||
let slug = path.parse(jsonFile).name
|
||||
let node = {slug: slug}
|
||||
const slug = path.parse(jsonFile).name
|
||||
const node = { slug: slug }
|
||||
slugs.push(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return slugs
|
||||
}
|
||||
|
||||
export async function getAllBlogPostsFromSource(datocmsFilters: any): Promise<any> {
|
||||
export async function getAllBlogPostsFromSource(
|
||||
datocmsFilters: any
|
||||
): Promise<any> {
|
||||
let allBlogPostsFromSource: any = {}
|
||||
|
||||
if (process.env.NEXT_PUBLIC_DATOCMS_BYPASS_TYPE === 'local_json') {
|
||||
@ -352,37 +368,41 @@ export async function getAllBlogPostsFromSource(datocmsFilters: any): Promise<an
|
||||
return allBlogPostsFromSource
|
||||
}
|
||||
|
||||
async function getSingleBlogPostJsonBySlug(slug: string): Promise<any> {
|
||||
let jsonDirectory = getBlogJsonDirectoryPath()
|
||||
let jsonFile = slug + '.json'
|
||||
let jsonPath = path.join(jsonDirectory, jsonFile)
|
||||
async function getSingleBlogPostJsonBySlug(
|
||||
slug: string
|
||||
): Promise<any> {
|
||||
const jsonDirectory = getBlogJsonDirectoryPath()
|
||||
const jsonFile = slug + '.json'
|
||||
const jsonPath = path.join(jsonDirectory, jsonFile)
|
||||
let blogPost: any = {}
|
||||
|
||||
try {
|
||||
let fileRawContents = await fs.readFile(jsonPath, 'utf8')
|
||||
let fileJsonContents = JSON.parse(fileRawContents)
|
||||
const fileRawContents = await fs.readFile(jsonPath, 'utf8')
|
||||
const fileJsonContents = JSON.parse(fileRawContents)
|
||||
blogPost = pluckBlogPostData(fileJsonContents)
|
||||
//-----continue to enforce standard set by forceBlogPostsJsonSlugIntegrity()
|
||||
blogPost.slug = slug
|
||||
blogPost.slug = slug
|
||||
} catch (e) {
|
||||
console.log('Failed to open or parse JSON for file ' + jsonPath)
|
||||
console.log('JSON parse attempt resulted in the following error:')
|
||||
console.log(e)
|
||||
//console.log('Failed to open or parse JSON for file ' + jsonPath)
|
||||
//console.log('JSON parse attempt resulted in the following error:')
|
||||
//console.log(e)
|
||||
}
|
||||
|
||||
return blogPost
|
||||
}
|
||||
|
||||
export async function getSingleBlogPostBySlugFromSource(slug: string): Promise<any> {
|
||||
export async function getSingleBlogPostBySlugFromSource(
|
||||
slug: string
|
||||
): Promise<any> {
|
||||
let blogPostJson: any = {}
|
||||
|
||||
if (process.env.NEXT_PUBLIC_DATOCMS_BYPASS_TYPE === 'local_json') {
|
||||
try {
|
||||
blogPostJson = await getSingleBlogPostJsonBySlug(slug)
|
||||
if (process.env.NEXT_PUBLIC_DATOCMS_BYPASS_TYPE === 'local_json') {
|
||||
try {
|
||||
blogPostJson = await getSingleBlogPostJsonBySlug(slug)
|
||||
} catch (e) {
|
||||
console.log('Failed pull blog post with slug ' + slug)
|
||||
console.log('The attempt resulted in the following error:')
|
||||
console.log(e)
|
||||
//console.log('Failed pull blog post with slug ' + slug)
|
||||
//console.log('The attempt resulted in the following error:')
|
||||
//console.log(e)
|
||||
}
|
||||
} else {
|
||||
blogPostJson = await (await cms().SingleBlogPost({ slug })).blogPost
|
||||
@ -391,34 +411,39 @@ export async function getSingleBlogPostBySlugFromSource(slug: string): Promise<a
|
||||
return blogPostJson
|
||||
}
|
||||
|
||||
function getBlogPostCategorySlugs(blogPostJson: any) {
|
||||
let categories = []
|
||||
function getBlogPostCategorySlugs(
|
||||
blogPostJson: any
|
||||
) {
|
||||
const categories = []
|
||||
|
||||
try {
|
||||
let categoryNode = blogPostJson.category
|
||||
const categoryNode = blogPostJson.category
|
||||
for (let i = 0; i < categoryNode.length; i++) {
|
||||
let category = categoryNode[i].slug
|
||||
const category = categoryNode[i].slug
|
||||
categories.push(category)
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('Failed pull blog post categories')
|
||||
console.log('The attempt resulted in the following error:')
|
||||
console.log(e)
|
||||
//console.log('Failed pull blog post categories')
|
||||
//console.log('The attempt resulted in the following error:')
|
||||
//console.log(e)
|
||||
}
|
||||
|
||||
return categories
|
||||
}
|
||||
|
||||
export async function getRelatedBlogPosts(blogPostJson: any, matchCount: number): Promise<any> {
|
||||
let relatedBlogPosts = []
|
||||
let reservedSlugs = []
|
||||
let matchedCount = 0
|
||||
let matchCategories = getBlogPostCategorySlugs(blogPostJson)
|
||||
let blogPosts = await getAllBlogPostsJson()
|
||||
let blogPostsData = blogPosts.data
|
||||
export async function getRelatedBlogPosts(
|
||||
blogPostJson: any,
|
||||
matchCount: number
|
||||
): Promise<any> {
|
||||
const relatedBlogPosts = []
|
||||
const reservedSlugs = []
|
||||
let matchedCount = 0
|
||||
const matchCategories = getBlogPostCategorySlugs(blogPostJson)
|
||||
const blogPosts = await getAllBlogPostsJson()
|
||||
const blogPostsData = blogPosts.data
|
||||
let candidateBlogPost: any = {}
|
||||
let candidateBlogPostSlug = ''
|
||||
let slug = blogPostJson.slug
|
||||
const slug = blogPostJson.slug
|
||||
|
||||
if (matchCategories.length > 0) {
|
||||
reservedSlugs.push(slug)
|
||||
@ -427,12 +452,15 @@ export async function getRelatedBlogPosts(blogPostJson: any, matchCount: number)
|
||||
candidateBlogPostSlug = candidateBlogPost.slug
|
||||
if (matchedCount >= matchCount) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if (reservedSlugs.includes(candidateBlogPostSlug) === false) {
|
||||
let candidateCategories = getBlogPostCategorySlugs(candidateBlogPost)
|
||||
const candidateCategories = getBlogPostCategorySlugs(candidateBlogPost)
|
||||
for (let j = 0; j < matchCategories.length; j++) {
|
||||
let matchCategory = matchCategories[j]
|
||||
if (candidateCategories.includes(matchCategory) === true && reservedSlugs.includes(candidateBlogPostSlug) === false) {
|
||||
const matchCategory = matchCategories[j]
|
||||
if (
|
||||
candidateCategories.includes(matchCategory) === true &&
|
||||
reservedSlugs.includes(candidateBlogPostSlug) === false
|
||||
) {
|
||||
relatedBlogPosts.push(candidateBlogPost)
|
||||
reservedSlugs.push(candidateBlogPostSlug)
|
||||
matchedCount++
|
||||
@ -450,11 +478,11 @@ export async function getRelatedBlogPosts(blogPostJson: any, matchCount: number)
|
||||
candidateBlogPostSlug = candidateBlogPost.slug
|
||||
if (matchedCount >= matchCount) {
|
||||
break
|
||||
}
|
||||
if (reservedSlugs.includes(candidateBlogPostSlug) === false) {
|
||||
}
|
||||
if (reservedSlugs.includes(candidateBlogPostSlug) === false) {
|
||||
relatedBlogPosts.push(candidateBlogPost)
|
||||
reservedSlugs.push(candidateBlogPostSlug)
|
||||
matchedCount++
|
||||
matchedCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -470,8 +498,8 @@ function getBlogCategoriesJsonDirectoryPath() {
|
||||
function pluckBlogCategoriesData(json: any) {
|
||||
let plucked = {}
|
||||
|
||||
if('data' in json){
|
||||
if('category' in json.data) {
|
||||
if ('data' in json) {
|
||||
if ('category' in json.data) {
|
||||
plucked = json.data.category
|
||||
}
|
||||
}
|
||||
@ -480,7 +508,7 @@ function pluckBlogCategoriesData(json: any) {
|
||||
}
|
||||
|
||||
function getRequiedBlogBlogCategoryNodes() {
|
||||
let nodes = []
|
||||
const nodes = []
|
||||
|
||||
nodes.push('slug')
|
||||
nodes.push('title')
|
||||
@ -489,9 +517,13 @@ function getRequiedBlogBlogCategoryNodes() {
|
||||
}
|
||||
|
||||
export async function getAllBlogCategoriesJson(): Promise<any[]> {
|
||||
let jsonDirectory = getBlogCategoriesJsonDirectoryPath()
|
||||
let validationNodes = getRequiedBlogBlogCategoryNodes()
|
||||
let allBlogCategoriesJson: any[] = await getJsonItemsFromDirectory(jsonDirectory, pluckBlogCategoriesData, validationNodes)
|
||||
const jsonDirectory = getBlogCategoriesJsonDirectoryPath()
|
||||
const validationNodes = getRequiedBlogBlogCategoryNodes()
|
||||
const allBlogCategoriesJson: any[] = await getJsonItemsFromDirectory(
|
||||
jsonDirectory,
|
||||
pluckBlogCategoriesData,
|
||||
validationNodes
|
||||
)
|
||||
|
||||
return allBlogCategoriesJson
|
||||
}
|
||||
@ -501,8 +533,8 @@ export async function getAllBlogPostsCategoriesFromSource(): Promise<any> {
|
||||
|
||||
if (process.env.NEXT_PUBLIC_DATOCMS_BYPASS_TYPE === 'local_json') {
|
||||
allBlogPostsCategoriesFromSource = await getAllBlogCategoriesJson()
|
||||
//let requestResults = await request(AllCategoriesQuery)
|
||||
//allBlogPostsCategoriesFromSource = requestResults.allCategories
|
||||
//let requestResults = await request(AllCategoriesQuery)
|
||||
//allBlogPostsCategoriesFromSource = requestResults.allCategories
|
||||
} else {
|
||||
allBlogPostsCategoriesFromSource = await serverGetBlogPostsCategories()
|
||||
}
|
||||
@ -518,8 +550,8 @@ function getEventsJsonDirectoryPath() {
|
||||
function pluckEventData(json: any) {
|
||||
let plucked = {}
|
||||
|
||||
if('data' in json){
|
||||
if('event' in json.data) {
|
||||
if 'data' in json) {
|
||||
if ('event' in json.data) {
|
||||
plucked = json.data.event
|
||||
}
|
||||
}
|
||||
@ -528,7 +560,7 @@ function pluckEventData(json: any) {
|
||||
}
|
||||
|
||||
function getRequiedEventNodes() {
|
||||
let nodes = []
|
||||
const nodes = []
|
||||
|
||||
nodes.push('title')
|
||||
nodes.push('eventLocation')
|
||||
@ -539,17 +571,26 @@ function getRequiedEventNodes() {
|
||||
}
|
||||
|
||||
function sortEventsJsonByStartDate(json: any[]) {
|
||||
let sortedJson: any[] = json.slice().sort((a: any, b: any) => datocmsDateToIng(b.eventStartdate) - datocmsDateToIng(a.eventStartdate))
|
||||
let sortedJson: any[] = json
|
||||
.slice()
|
||||
.sort(
|
||||
(a: any, b: any) =>
|
||||
datocmsDateToIng(b.eventStartdate) - datocmsDateToIng(a.eventStartdate)
|
||||
)
|
||||
|
||||
return sortedJson
|
||||
}
|
||||
|
||||
async function getAllEventsJson(): Promise<any> {
|
||||
let jsonDirectory = getEventsJsonDirectoryPath()
|
||||
let validationNodes = getRequiedEventNodes()
|
||||
let events: any[] = await getJsonItemsFromDirectory(jsonDirectory, pluckEventData, validationNodes)
|
||||
let sortedEvents: any[] = sortEventsJsonByStartDate(events)
|
||||
let allEventsJson = {allEvents: sortedEvents}
|
||||
const jsonDirectory = getEventsJsonDirectoryPath()
|
||||
const validationNodes = getRequiedEventNodes()
|
||||
const events: any[] = await getJsonItemsFromDirectory(
|
||||
jsonDirectory,
|
||||
pluckEventData,
|
||||
validationNodes
|
||||
)
|
||||
const sortedEvents: any[] = sortEventsJsonByStartDate(events)
|
||||
const allEventsJson = { allEvents: sortedEvents }
|
||||
|
||||
return allEventsJson
|
||||
}
|
||||
@ -562,8 +603,8 @@ function getPositionsJsonDirectoryPath() {
|
||||
function pluckPositionData(json: any) {
|
||||
let plucked = {}
|
||||
|
||||
if('data' in json){
|
||||
if('position' in json.data) {
|
||||
if ('data' in json) {
|
||||
if ('position' in json.data) {
|
||||
plucked = json.data.position
|
||||
}
|
||||
}
|
||||
@ -572,7 +613,7 @@ function pluckPositionData(json: any) {
|
||||
}
|
||||
|
||||
function getRequiedPositionNodes() {
|
||||
let nodes = []
|
||||
const nodes = []
|
||||
|
||||
nodes.push('id')
|
||||
nodes.push('positionName')
|
||||
@ -582,17 +623,23 @@ function getRequiedPositionNodes() {
|
||||
}
|
||||
|
||||
function sortPositionsJsonById(json: any[]) {
|
||||
let sortedJson: any[] = json.slice().sort((a: any, b: any) => parseInt(a.id) - parseInt(b.id))
|
||||
const sortedJson: any[] = json
|
||||
.slice()
|
||||
.sort((a: any, b: any) => parseInt(a.id) - parseInt(b.id))
|
||||
|
||||
return sortedJson
|
||||
}
|
||||
|
||||
async function getAllPositionsJson(): Promise<any> {
|
||||
let jsonDirectory = getPositionsJsonDirectoryPath()
|
||||
let validationNodes = getRequiedPositionNodes()
|
||||
let positions: any[] = await getJsonItemsFromDirectory(jsonDirectory, pluckPositionData, validationNodes)
|
||||
let sortedPositions: any[] = sortPositionsJsonById(positions)
|
||||
let allPositionsJson = {allPositions: sortedPositions}
|
||||
const jsonDirectory = getPositionsJsonDirectoryPath()
|
||||
const validationNodes = getRequiedPositionNodes()
|
||||
const positions: any[] = await getJsonItemsFromDirectory(
|
||||
jsonDirectory,
|
||||
pluckPositionData,
|
||||
validationNodes
|
||||
)
|
||||
const sortedPositions: any[] = sortPositionsJsonById(positions)
|
||||
const allPositionsJson = { allPositions: sortedPositions }
|
||||
|
||||
return allPositionsJson
|
||||
}
|
||||
@ -605,8 +652,8 @@ function getPressReleasesJsonDirectoryPath() {
|
||||
function pluckPressReleaseData(json: any) {
|
||||
let plucked = {}
|
||||
|
||||
if('data' in json){
|
||||
if('pressRelease' in json.data) {
|
||||
if ('data' in json) {
|
||||
if ('pressRelease' in json.data) {
|
||||
plucked = json.data.pressRelease
|
||||
}
|
||||
}
|
||||
@ -615,7 +662,7 @@ function pluckPressReleaseData(json: any) {
|
||||
}
|
||||
|
||||
function getRequiedPressReleaseNodes() {
|
||||
let nodes = []
|
||||
const nodes = []
|
||||
|
||||
nodes.push('id')
|
||||
nodes.push('title')
|
||||
@ -626,17 +673,25 @@ function getRequiedPressReleaseNodes() {
|
||||
}
|
||||
|
||||
function sortPressReleasesJsonByDate(json: any[]) {
|
||||
let sortedJson: any[] = json.slice().sort((a: any, b: any) => datocmsDateToIng(b.date) - datocmsDateToIng(a.date))
|
||||
let sortedJson: any[] = json
|
||||
.slice()
|
||||
.sort(
|
||||
(a: any, b: any) => datocmsDateToIng(b.date) - datocmsDateToIng(a.date)
|
||||
)
|
||||
|
||||
return sortedJson
|
||||
}
|
||||
|
||||
async function getAllPressReleasesJson(): Promise<any> {
|
||||
let jsonDirectory = getPressReleasesJsonDirectoryPath()
|
||||
let validationNodes = getRequiedPressReleaseNodes()
|
||||
let pressReleases: any[] = await getJsonItemsFromDirectory(jsonDirectory, pluckPressReleaseData, validationNodes)
|
||||
let sortedPressReleases: any[] = sortPressReleasesJsonByDate(pressReleases)
|
||||
let allPressReleasesJson = {allPressReleases: sortedPressReleases}
|
||||
const jsonDirectory = getPressReleasesJsonDirectoryPath()
|
||||
const validationNodes = getRequiedPressReleaseNodes()
|
||||
const pressReleases: any[] = await getJsonItemsFromDirectory(
|
||||
jsonDirectory,
|
||||
pluckPressReleaseData,
|
||||
validationNodes
|
||||
)
|
||||
const sortedPressReleases: any[] = sortPressReleasesJsonByDate(pressReleases)
|
||||
const allPressReleasesJson = { allPressReleases: sortedPressReleases }
|
||||
|
||||
return allPressReleasesJson
|
||||
}
|
||||
@ -649,8 +704,8 @@ function getTeamsJsonDirectoryPath() {
|
||||
function pluckTeamData(json: any) {
|
||||
let plucked = {}
|
||||
|
||||
if('data' in json){
|
||||
if('team' in json.data) {
|
||||
if ('data' in json) {
|
||||
if ('team' in json.data) {
|
||||
plucked = json.data.team
|
||||
}
|
||||
}
|
||||
@ -659,7 +714,7 @@ function pluckTeamData(json: any) {
|
||||
}
|
||||
|
||||
function getRequiedTeamNodes() {
|
||||
let nodes = []
|
||||
const nodes = []
|
||||
|
||||
nodes.push('id')
|
||||
nodes.push('memberName')
|
||||
@ -668,17 +723,23 @@ function getRequiedTeamNodes() {
|
||||
}
|
||||
|
||||
function sortTeamsJsonById(json: any[]) {
|
||||
let sortedJson: any[] = json.slice().sort((a: any, b: any) => parseInt(a.id) - parseInt(b.id))
|
||||
const sortedJson: any[] = json
|
||||
.slice()
|
||||
.sort((a: any, b: any) => parseInt(a.id) - parseInt(b.id))
|
||||
|
||||
return sortedJson
|
||||
}
|
||||
|
||||
async function getAllTeamsJson(): Promise<any> {
|
||||
let jsonDirectory = getTeamsJsonDirectoryPath()
|
||||
let validationNodes = getRequiedTeamNodes()
|
||||
let teams: any[] = await getJsonItemsFromDirectory(jsonDirectory, pluckTeamData, validationNodes)
|
||||
const jsonDirectory = getTeamsJsonDirectoryPath()
|
||||
const validationNodes = getRequiedTeamNodes()
|
||||
const teams: any[] = await getJsonItemsFromDirectory(
|
||||
jsonDirectory,
|
||||
pluckTeamData,
|
||||
validationNodes
|
||||
)
|
||||
let sortedTeams: any[] = sortTeamsJsonById(teams)
|
||||
let allTeamsJson = {allTeams: sortedTeams}
|
||||
let allTeamsJson = { allTeams: sortedTeams }
|
||||
|
||||
return allTeamsJson
|
||||
}
|
||||
@ -691,8 +752,8 @@ function getTestimonialsJsonDirectoryPath() {
|
||||
function pluckTestimonialData(json: any) {
|
||||
let plucked = {}
|
||||
|
||||
if('data' in json){
|
||||
if('testimonial' in json.data) {
|
||||
if ('data' in json) {
|
||||
if ('testimonial' in json.data) {
|
||||
plucked = json.data.testimonial
|
||||
}
|
||||
}
|
||||
@ -701,7 +762,7 @@ function pluckTestimonialData(json: any) {
|
||||
}
|
||||
|
||||
function getRequiedTestimonialNodes() {
|
||||
let nodes = []
|
||||
const nodes = []
|
||||
|
||||
nodes.push('id')
|
||||
nodes.push('testimonialImage')
|
||||
@ -712,17 +773,23 @@ function getRequiedTestimonialNodes() {
|
||||
}
|
||||
|
||||
function sortTestimonialsJsonById(json: any[]) {
|
||||
let sortedJson: any[] = json.slice().sort((a: any, b: any) => parseInt(a.id) - parseInt(b.id))
|
||||
const sortedJson: any[] = json
|
||||
.slice()
|
||||
.sort((a: any, b: any) => parseInt(a.id) - parseInt(b.id))
|
||||
|
||||
return sortedJson
|
||||
}
|
||||
|
||||
async function getAllTestimonialsJson(): Promise<any> {
|
||||
let jsonDirectory = getTestimonialsJsonDirectoryPath()
|
||||
let validationNodes = getRequiedTestimonialNodes()
|
||||
let testimonials: any[] = await getJsonItemsFromDirectory(jsonDirectory, pluckTestimonialData, validationNodes)
|
||||
let sortedTestimonals: any[] = sortTestimonialsJsonById(testimonials)
|
||||
let allTestimonialsJson = {allTestimonials: sortedTestimonals}
|
||||
const jsonDirectory = getTestimonialsJsonDirectoryPath()
|
||||
const validationNodes = getRequiedTestimonialNodes()
|
||||
const testimonials: any[] = await getJsonItemsFromDirectory(
|
||||
jsonDirectory,
|
||||
pluckTestimonialData,
|
||||
validationNodes
|
||||
)
|
||||
const sortedTestimonals: any[] = sortTestimonialsJsonById(testimonials)
|
||||
const allTestimonialsJson = {allTestimonials: sortedTestimonals}
|
||||
|
||||
return allTestimonialsJson
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user