-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOEOPSFY24-375 | restructure timeline data and add json validation
- Loading branch information
1 parent
4ec3807
commit df10595
Showing
19 changed files
with
164 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[{ | ||
"year": "1990", | ||
"heading": "The Beginning", | ||
"body": "In 1990, the company was founded with a vision to revolutionize the tech industry.", | ||
"image": "https://placecats.com/neo/300/200" | ||
}, | ||
{ | ||
"year": "1990", | ||
"heading": "Exploring the reengineering of immune cells", | ||
"body": "The Sarafan ChEM-H Institute scholar is building a multidisciplinary lab to explore the reengineering of immune cells. Before coming to Stanford, she says, “I was thinking in terms of understanding. Now I feel that I can start thinking in terms of creating.", | ||
"image": "/soe-centennial-nextjs/assets/images/lt-flynn-1994.jpeg" | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2000", | ||
"heading": "The Growth Phase", | ||
"dek": "Expanding Horizons", | ||
"body": "By 2000, the company had grown exponentially, reaching international markets.", | ||
"href": "https://example.com/2000", | ||
"image": "https://placecats.com/millie/300/200", | ||
"uuid": 2 | ||
"image": "https://placecats.com/millie/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2030", | ||
"year": "2001", | ||
"heading": "The Sustainability Push", | ||
"dek": "Green Technology", | ||
"body": "The 2030s marked a major commitment to sustainability, with innovative green technology solutions and global environmental initiatives.", | ||
"href": "https://example.com/2030", | ||
"image": "https://placecats.com/bella/300/200", | ||
"uuid": 13 | ||
"image": "https://placecats.com/bella/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2040", | ||
"year": "2005", | ||
"heading": "The Global Frontier", | ||
"dek": "Space Exploration", | ||
"body": "By 2040, the company expanded into space exploration, developing technologies to aid in interplanetary travel and settlement.", | ||
"href": null, | ||
"image": "https://placecats.com/neo_2/300/200", | ||
"uuid": 14 | ||
"image": "https://placecats.com/neo_2/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2010", | ||
"heading": "The Digital Age", | ||
"dek": "Embracing Innovation", | ||
"body": "The 2010s marked the company's shift to digital-first strategies, leading the way in AI and machine learning.", | ||
"href": null, | ||
"image": "https://placecats.com/neo_banana/300/200", | ||
"uuid": 3 | ||
"image": "https://placecats.com/neo_banana/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2021", | ||
"heading": "New Innovations", | ||
"dek": "Pushing Boundaries", | ||
"body": "In 2021, the company introduced groundbreaking technologies that set a new industry standard.", | ||
"href": "https://example.com/2021", | ||
"image": "https://placecats.com/millie/300/200", | ||
"uuid": 4 | ||
"image": "https://placecats.com/millie/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2022", | ||
"heading": "Sustainability Focus", | ||
"dek": "Eco-Friendly Solutions", | ||
"body": "The company made strides towards sustainability, implementing green technologies across its product line.", | ||
"href": "https://example.com/2022", | ||
"image": "https://placecats.com/neo_banana/300/200", | ||
"uuid": 5 | ||
"image": "https://placecats.com/neo_banana/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2023", | ||
"heading": "AI Revolution", | ||
"dek": "A Step into the Future", | ||
"body": "By 2023, the company had integrated advanced AI into all its platforms, driving new levels of innovation.", | ||
"href": "https://example.com/2023", | ||
"image": "https://placecats.com/neo/300/200", | ||
"uuid": 6 | ||
"image": "https://placecats.com/neo/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2024", | ||
"heading": "Global Expansion", | ||
"dek": "Reaching New Markets", | ||
"body": "The company continued its expansion into new global markets, making its products available to more people than ever.", | ||
"href": "https://example.com/2024", | ||
"image": "https://placecats.com/millie/300/200", | ||
"uuid": 7 | ||
"image": "https://placecats.com/millie/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2025", | ||
"heading": "Milestone Achievement", | ||
"dek": "Celebrating 35 Years", | ||
"body": "In 2025, the company celebrated its 35th anniversary, marking decades of innovation and success.", | ||
"href": "https://example.com/2025", | ||
"image": "https://placecats.com/bella/300/200", | ||
"uuid": 8 | ||
"image": "https://placecats.com/bella/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2026", | ||
"heading": "Quantum Leap", | ||
"dek": "The Next Frontier", | ||
"body": "The company made its first foray into quantum computing, pushing the boundaries of what was possible.", | ||
"href": "https://example.com/2026", | ||
"image": "https://placecats.com/neo/300/200", | ||
"uuid": 9 | ||
"image": "https://placecats.com/neo/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2027", | ||
"heading": "Community Outreach", | ||
"dek": "Giving Back", | ||
"body": "With a focus on corporate responsibility, the company launched new initiatives to support underserved communities.", | ||
"href": "https://example.com/2027", | ||
"image": "https://placecats.com/neo_banana/300/200", | ||
"uuid": 10 | ||
"image": "https://placecats.com/neo_banana/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2028", | ||
"heading": "AI-Powered Solutions", | ||
"dek": "Automation Everywhere", | ||
"body": "In 2028, the company unveiled a suite of AI-powered tools aimed at transforming everyday life.", | ||
"href": "https://example.com/2028", | ||
"image": "https://placecats.com/millie/300/200", | ||
"uuid": 11 | ||
"image": "https://placecats.com/millie/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
{ | ||
"year": "2029", | ||
"heading": "Pioneering Robotics", | ||
"dek": "The Future is Here", | ||
"body": "The company became a leader in robotics, developing advanced systems for both home and industry use.", | ||
"href": "https://example.com/2029", | ||
"image": "https://placecats.com/neo_banana/300/200", | ||
"uuid": 12 | ||
"image": "https://placecats.com/neo_banana/300/200" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* eslint-disable no-console */ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import Ajv from 'ajv'; | ||
|
||
// Schema for the timeline items | ||
const schema = { | ||
oneOf: [ | ||
{ | ||
// Case when the root is a single object | ||
type: 'object', | ||
properties: { | ||
year: { type: 'string', pattern: '^(19|20)\\d{2}$' }, | ||
heading: { type: 'string' }, | ||
body: { type: 'string' }, | ||
image: { type: 'string' }, // @TODO: Additional image path validation can be configured here | ||
}, | ||
required: ['year', 'heading', 'body', 'image'], | ||
additionalProperties: false, | ||
}, | ||
{ | ||
// Case when the root is an array of objects | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
year: { type: 'string', pattern: '^(19|20)\\d{2}$' }, | ||
heading: { type: 'string' }, | ||
body: { type: 'string' }, | ||
image: { type: 'string' }, // @TODO: Additional image path validation can be configured here | ||
}, | ||
required: ['year', 'heading', 'body', 'image'], | ||
additionalProperties: false, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
// Validate timeline data based on defined schema above | ||
const validateTimeline = async () => { | ||
const directoryPath = path.join(process.cwd(), 'data/timeline'); | ||
const ajv = new Ajv(); | ||
const validate = ajv.compile(schema); | ||
|
||
let isValid = true; | ||
|
||
// Recursively fetch all JSON files from the timeline directory and subdirectories | ||
const getAllJsonFiles = (dirPath) => { | ||
const items = fs.readdirSync(dirPath); | ||
let files = []; | ||
items.forEach(item => { | ||
const fullPath = path.join(dirPath, item); | ||
const stat = fs.statSync(fullPath); | ||
if (stat.isDirectory()) { | ||
files = [...files, ...getAllJsonFiles(fullPath)]; | ||
} else if (stat.isFile() && item.endsWith('.json')) { | ||
files.push(fullPath); | ||
} | ||
}); | ||
return files; | ||
}; | ||
|
||
// Fetch all the JSON files in the timeline directory and its subdirectories | ||
const jsonFiles = getAllJsonFiles(directoryPath); | ||
|
||
// Review each JSON file | ||
for (const filePath of jsonFiles) { | ||
const fileContents = fs.readFileSync(filePath, 'utf-8'); | ||
|
||
try { | ||
const data = JSON.parse(fileContents); | ||
const valid = validate(data); | ||
|
||
if (!valid) { | ||
isValid = false; | ||
console.error(`Validation errors in file: ${filePath}`); | ||
console.error(validate.errors); | ||
} | ||
} catch (error) { | ||
isValid = false; | ||
console.error(`Error parsing JSON in file: ${filePath}`); | ||
console.error(error.message); | ||
} | ||
} | ||
|
||
if (isValid) { | ||
console.log('All timeline JSON files are valid!'); | ||
} else { | ||
console.error('Some files failed validation.'); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
// Run validation function | ||
validateTimeline(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.