1- import { Folder , FileText , ChevronRight , Home } from ' lucide-react' ;
2- import fs from 'fs' ;
3- import path from ' path' ;
4- import Link from ' next/link' ;
5- import { Metadata } from ' next' ;
6-
1+ import { Folder , FileText , ChevronRight , Home } from " lucide-react" ;
2+ import fs from "fs" ;
3+ import path from " path" ;
4+ import Link from " next/link" ;
5+ import { Metadata } from " next" ;
6+ import styles from "./Explorer.module.css" ; // Assuming you have a CSS module for styles
77
88export const metadata : Metadata = {
9- title : ' AcademiaDrive Explorer' ,
9+ title : " AcademiaDrive Explorer" ,
1010} ;
1111
1212type ExplorerPageProps = {
@@ -18,7 +18,7 @@ type ExplorerPageProps = {
1818} ;
1919
2020export async function getStaticPaths ( ) {
21- const basePath = path . join ( process . cwd ( ) , ' public/academiadrive' ) ;
21+ const basePath = path . join ( process . cwd ( ) , " public/academiadrive" ) ;
2222
2323 const getDirectories = ( dir : string ) : string [ ] => {
2424 const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
@@ -27,7 +27,9 @@ export async function getStaticPaths() {
2727 entries . forEach ( ( entry ) => {
2828 const fullPath = path . join ( dir , entry . name ) ;
2929 if ( entry . isDirectory ( ) ) {
30- directories . push ( fullPath . replace ( basePath , '' ) . replace ( / \\ / g, '/' ) . slice ( 1 ) ) ;
30+ directories . push (
31+ fullPath . replace ( basePath , "" ) . replace ( / \\ / g, "/" ) . slice ( 1 )
32+ ) ;
3133 directories = directories . concat ( getDirectories ( fullPath ) ) ; // Recursively add directories
3234 }
3335 } ) ;
@@ -37,15 +39,19 @@ export async function getStaticPaths() {
3739
3840 const directories = getDirectories ( basePath ) ;
3941 const paths = directories . map ( ( dir ) => ( {
40- params : { slug : dir . split ( '/' ) } ,
42+ params : { slug : dir . split ( "/" ) } ,
4143 } ) ) ;
4244
4345 return { paths, fallback : false } ;
4446}
4547
46- export async function getStaticProps ( { params } : { params : { slug : string [ ] } } ) {
48+ export async function getStaticProps ( {
49+ params,
50+ } : {
51+ params : { slug : string [ ] } ;
52+ } ) {
4753 const { slug = [ ] } = params ;
48- const basePath = path . join ( process . cwd ( ) , ' public/academiadrive' , ...slug ) ;
54+ const basePath = path . join ( process . cwd ( ) , " public/academiadrive" , ...slug ) ;
4955
5056 let entries : fs . Dirent [ ] = [ ] ;
5157 try {
@@ -59,151 +65,100 @@ export async function getStaticProps({ params }: { params: { slug: string[] } })
5965 . map ( ( dir ) => ( { name : dir . name , path : path . join ( basePath , dir . name ) } ) ) ;
6066
6167 const pdfs = entries
62- . filter ( ( e ) => e . isFile ( ) && e . name . toLowerCase ( ) . endsWith ( ' .pdf' ) )
68+ . filter ( ( e ) => e . isFile ( ) && e . name . toLowerCase ( ) . endsWith ( " .pdf" ) )
6369 . map ( ( pdf ) => ( { name : pdf . name , path : path . join ( basePath , pdf . name ) } ) ) ;
6470
6571 return {
6672 props : { params, directories, pdfs } ,
6773 } ;
6874}
6975
70-
71- export default function ExplorerPage ( { params, directories, pdfs } : ExplorerPageProps ) {
76+ export default function ExplorerPage ( {
77+ params,
78+ directories,
79+ pdfs,
80+ } : ExplorerPageProps ) {
7281 const { slug = [ ] } = params ;
73- const currentPath = slug . join ( '/' ) ;
7482
7583 return (
76- < main className = "min-h-screen bg-gradient-to-br from-gray-50 to-gray-100 p-4 md: p-8" >
84+ < main className = "min-h-screen bg-gradient-to-b from-white to-gray-50 p-8" >
7785 < div className = "max-w-6xl mx-auto" >
78- < div className = "mb-8 text-center" >
79- < h1 className = "text-3xl md:text-4xl font-bold bg-clip-text text-transparent bg-gradient-to-r from-blue-600 to-indigo-700 mb-2" >
80- AcademiaDrive Explorer
81- </ h1 >
82- < p className = "text-gray-500 max-w-2xl mx-auto" >
83- Browse through our organized collection of study materials and resources
84- </ p >
86+ < h1 className = "text-center text-3xl md:text-4xl font-semibold text-gray-900 mb-1" >
87+ Study Material
88+ </ h1 >
89+
90+ < div
91+ className = { `${ styles . subheading } text-center text-sm text-gray-600 mb-8` }
92+ >
93+ { slug . length > 0 ? slug . join ( " / " ) : "SELECT A CATEGORY" }
8594 </ div >
8695
87- { /* Breadcrumb Navigation */ }
88- < div className = "mb-6 flex items-center text-sm text-gray-500 bg-white rounded-lg shadow-sm p-3" >
89- < Link href = "/explorer" className = "flex items-center text-blue-600 hover:text-blue-800" >
90- < Home size = { 16 } className = "mr-1" />
91- < span > Root</ span >
92- </ Link >
93- { slug . map ( ( segment , index ) => (
94- < div key = { index } className = "flex items-center" >
95- < ChevronRight size = { 16 } className = "mx-2 text-gray-400" />
96- < Link
97- href = { `/explorer/${ slug . slice ( 0 , index + 1 ) . join ( '/' ) } ` }
98- className = { `${ index === slug . length - 1 ? 'text-gray-700 font-medium' : 'text-blue-600 hover:text-blue-800' } ` }
96+ { /* Folders / Directories */ }
97+ { /* Directories */ }
98+ { directories . length > 0 && (
99+ < div className = "flex flex-wrap gap-4 justify-center mb-6" >
100+ { directories . map ( ( dir ) => (
101+ < Link
102+ key = { dir . name }
103+ href = { `/explorer/${ [ ...slug , dir . name ] . join ( "/" ) } ` }
104+ className = "block"
105+ aria-label = { `Open ${ dir . name } ` }
99106 >
100- { segment }
107+ < div
108+ role = "button"
109+ title = { dir . name }
110+ className = "w-58 h-20 flex items-center justify-center rounded-lg border border-gray-300 bg-white px-3 text-center text-sm md:text-base font-medium text-gray-900 shadow-sm hover:shadow-md hover:bg-blue-600 hover:text-white transition-colors duration-200"
111+ >
112+ < span className = " cardText " >
113+ { dir . name . replace ( / _ / g, "_\u200B" ) }
114+ </ span >
115+ </ div >
101116 </ Link >
102- </ div >
103- ) ) }
104- </ div >
105-
106- { /* Content Container */ }
107- < div className = "bg-white rounded-xl shadow-lg overflow-hidden" >
108- { /* Header with current path */ }
109- < div className = "border-b border-gray-100 p-4 bg-gray-50" >
110- < div className = "flex items-center" >
111- < Folder className = "text-blue-500 mr-2" size = { 20 } />
112- < span className = "font-medium text-gray-700 truncate" >
113- { slug . length > 0 ? slug . join ( ' / ' ) : 'All Categories' }
114- </ span >
115- < span className = "ml-auto text-xs text-gray-500 bg-gray-100 px-2 py-1 rounded" >
116- { directories . length } folders • { pdfs . length } files
117- </ span >
118- </ div >
117+ ) ) }
119118 </ div >
120-
121- { /* Folders Section */ }
122- { directories . length > 0 && (
123- < div className = "p-4" >
124- < h2 className = "text-lg font-semibold text-gray-700 mb-3 flex items-center" >
125- < span className = "bg-blue-100 text-blue-800 p-1 rounded mr-2" >
126- < Folder size = { 18 } />
127- </ span >
128- Folders
129- </ h2 >
130- < div className = "grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-3" >
131- { directories . map ( ( dir ) => (
132- < Link
133- key = { dir . name }
134- href = { `/explorer/${ [ ...slug , dir . name ] . join ( '/' ) } ` }
135- className = "group"
136- >
137- < div className = "border border-gray-200 rounded-lg p-4 transition-all duration-200 group-hover:border-blue-300 group-hover:shadow-md group-hover:bg-blue-50 h-full flex flex-col items-center" >
138- < div className = "bg-blue-100 p-3 rounded-full mb-3 text-blue-600 group-hover:text-blue-800" >
139- < Folder size = { 24 } />
140- </ div >
141- < span className = "text-gray-700 font-medium text-center text-sm truncate w-full" >
142- { dir . name }
143- </ span >
144- </ div >
145- </ Link >
146- ) ) }
147- </ div >
148- </ div >
149- ) }
150-
151- { /* PDFs Section */ }
152- { pdfs . length > 0 && (
153- < div className = "p-4 border-t border-gray-100" >
154- < h2 className = "text-lg font-semibold text-gray-700 mb-3 flex items-center" >
155- < span className = "bg-green-100 text-green-800 p-1 rounded mr-2" >
156- < FileText size = { 18 } />
157- </ span >
158- Study Materials
159- </ h2 >
160- < div className = "grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-3" >
161- { pdfs . map ( ( pdf ) => (
119+ ) }
120+
121+ { /* PDFs */ }
122+ { pdfs . length > 0 && (
123+ < >
124+ < h2 className = "text-center text-xl font-semibold mt-4 mb-4 text-gray-800" >
125+ PDFs Available
126+ </ h2 >
127+ < div className = "flex flex-wrap gap-4 justify-center" >
128+ { pdfs . map ( ( pdf ) => {
129+ const label = pdf . name . replace ( / \. p d f $ / i, "" ) ;
130+ return (
162131 < a
163132 key = { pdf . name }
164- href = { `/academiadrive/${ currentPath ? currentPath + '/' : '' } ${ pdf . name } ` }
133+ href = { `/academiadrive/${ [ ... slug , pdf . name ] . join ( "/" ) } ` }
165134 className = "block"
166135 download
136+ aria-label = { `Download ${ label } ` }
137+ title = { label }
167138 >
168- < div className = "border border-gray-200 rounded-lg p-4 transition-all duration-200 hover:border-green-300 hover:shadow-md hover:bg-green-50 flex items-start" >
169- < div className = "bg-green-100 p-2 rounded mr-3 text-green-600" >
170- < FileText size = { 20 } />
171- </ div >
172- < div className = "flex-1 min-w-0" >
173- < div className = "font-medium text-gray-800 truncate text-sm mb-1" >
174- { pdf . name . replace ( '.pdf' , '' ) }
175- </ div >
176- < div className = "text-xs text-gray-500 flex items-center" >
177- < span > PDF Document</ span >
178- < span className = "mx-2" > •</ span >
179- < span > { ( Math . random ( ) * 2 + 1 ) . toFixed ( 1 ) } MB</ span >
180- </ div >
181- </ div >
139+ < div className = "w-48 h-20 flex items-center justify-center rounded-lg border border-gray-300 bg-white px-3 text-center text-sm md:text-base font-medium text-gray-900 shadow-sm hover:shadow-md hover:bg-green-600 hover:text-white transition-colors duration-200" >
140+ < span className = "break-words whitespace-normal leading-tight" >
141+ { label . replace ( / _ / g, "_\u200B" ) }
142+ </ span >
182143 </ div >
183144 </ a >
184- ) ) }
185- </ div >
145+ ) ;
146+ } ) }
186147 </ div >
187- ) }
188-
189- { /* Empty State */ }
190- { directories . length === 0 && pdfs . length === 0 && (
191- < div className = "p-12 text-center" >
192- < div className = "mx-auto bg-gray-100 p-4 rounded-full w-16 h-16 flex items-center justify-center mb-4" >
193- < Folder className = "text-gray-400" size = { 24 } />
194- </ div >
195- < h3 className = "text-lg font-medium text-gray-700 mb-1" > Empty Folder</ h3 >
196- < p className = "text-gray-500 max-w-md mx-auto" >
197- This directory doesnt contain any folders or PDF files yet.
198- </ p >
199- </ div >
200- ) }
201- </ div >
202148
203- < footer className = "mt-8 text-center text-gray-500 text-sm" >
204- < p > AcademiaDrive Explorer • All materials are for educational purposes</ p >
205- </ footer >
149+ </ >
150+ ) }
151+
152+
153+
154+
155+ { /* Empty state */ }
156+ { directories . length === 0 && pdfs . length === 0 && (
157+ < p className = { `${ styles . footer } text-center text-gray-500 mt-8` } >
158+ No folders or PDFs found in this section.
159+ </ p >
160+ ) }
206161 </ div >
207162 </ main >
208163 ) ;
209- }
164+ }
0 commit comments