@@ -7,6 +7,13 @@ import Hero from "@/components/hero";
7
7
import Image from "next/image" ;
8
8
import HeadContent from "@/components/headContent" ;
9
9
10
+ // Function to get all projects from JSON files
11
+ const getAllProjects = ( ) => {
12
+ const pastProjects = JSON . parse ( fs . readFileSync ( path . join ( process . cwd ( ) , 'config' , 'pastProjects.json' ) , 'utf-8' ) ) ;
13
+ const currentProjects = JSON . parse ( fs . readFileSync ( path . join ( process . cwd ( ) , 'config' , 'currentProjects.json' ) , 'utf-8' ) ) ;
14
+ return [ ...pastProjects , ...currentProjects ] ;
15
+ } ;
16
+
10
17
function ProjectPage ( { content, title, images } ) {
11
18
const router = useRouter ( ) ;
12
19
const basePath = router . basePath ;
@@ -29,7 +36,14 @@ function ProjectPage({ content, title, images }) {
29
36
}
30
37
31
38
export async function getStaticProps ( { params } ) {
39
+ const allProjects = getAllProjects ( ) ;
32
40
const [ subdirectory , innerDir ] = params . slug ;
41
+ const project = allProjects . find ( proj => proj . subdirectory === subdirectory && proj . innerDir === innerDir ) ;
42
+
43
+ if ( ! project ) {
44
+ return { notFound : true } ;
45
+ }
46
+
33
47
const filePath = path . join ( process . cwd ( ) , 'content' , 'projects' , subdirectory , innerDir , 'writeup.md' ) ;
34
48
const fileContent = fs . readFileSync ( filePath , 'utf-8' ) ;
35
49
@@ -46,13 +60,13 @@ export async function getStaticProps({ params }) {
46
60
}
47
61
48
62
export async function getStaticPaths ( ) {
49
- const projectsDirectory = path . join ( process . cwd ( ) , "content" , "projects" ) ;
50
- const subdirectories = fs . readdirSync ( projectsDirectory , { withFileTypes : true } ) . filter ( dirent => dirent . isDirectory ( ) ) ;
63
+ const allProjects = getAllProjects ( ) ;
51
64
52
- const paths = subdirectories . flatMap ( subdirectory => {
53
- const innerDirectories = fs . readdirSync ( path . join ( projectsDirectory , subdirectory . name ) , { withFileTypes : true } ) . filter ( dirent => dirent . isDirectory ( ) ) ;
54
- return innerDirectories . map ( innerDir => ( { params : { slug : [ subdirectory . name , innerDir . name ] } } ) ) ;
55
- } ) ;
65
+ const paths = allProjects . map ( project => ( {
66
+ params : {
67
+ slug : [ project . subdirectory , project . innerDir ] ,
68
+ } ,
69
+ } ) ) ;
56
70
57
71
return {
58
72
paths,
0 commit comments