Skip to content

Commit

Permalink
SOEOPSFY24-375 | restructure timeline data and add json validation
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahongsf committed Dec 5, 2024
1 parent 4ec3807 commit df10595
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 77 deletions.
18 changes: 0 additions & 18 deletions data/timeline/1990.json

This file was deleted.

12 changes: 12 additions & 0 deletions data/timeline/1990s/1990.json
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"
}]
5 changes: 1 addition & 4 deletions data/timeline/2000.json → data/timeline/2000s/2000.json
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"
}
7 changes: 2 additions & 5 deletions data/timeline/2030.json → data/timeline/2000s/2001.json
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"
}
7 changes: 2 additions & 5 deletions data/timeline/2040.json → data/timeline/2000s/2005.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2010.json → data/timeline/2010s/2010.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2021.json → data/timeline/2020s/2021.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2022.json → data/timeline/2020s/2022.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2023.json → data/timeline/2020s/2023.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2024.json → data/timeline/2020s/2024.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2025.json → data/timeline/2020s/2025.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2026.json → data/timeline/2020s/2026.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2027.json → data/timeline/2020s/2027.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2028.json → data/timeline/2020s/2028.json
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"
}
5 changes: 1 addition & 4 deletions data/timeline/2029.json → data/timeline/2020s/2029.json
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"
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
"name": "soe-centennial-nextjs",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint:fix": "eslint \"app/**/*.{ts,tsx,js,jsx}\" --fix",
"typecheck": "tsc --noEmit",
"tsc": "tsc"
"tsc": "tsc",
"validate:timeline": "node scripts/validate-timeline.js"
},
"dependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0",
"@heroicons/react": "^2.1.5",
"@tailwindcss/container-queries": "^0.1.1",
"ajv": "^8.17.1",
"cnbuilder": "^3.1.0",
"flubber": "^0.4.2",
"framer-motion": "^12.0.0-alpha.1",
Expand Down
95 changes: 95 additions & 0 deletions scripts/validate-timeline.js
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();
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"module": "CommonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
Expand All @@ -26,14 +26,14 @@
"./*"
]
},
"target": "es6",
"target": "es6"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
, "scripts/validate-timeline.js" ],
"exclude": [
"node_modules"
]
Expand Down
Loading

0 comments on commit df10595

Please sign in to comment.