@@ -5,6 +5,8 @@ import { usePathname, useRouter } from "next/navigation";
5
5
import djStyles from "./devjourney.module.css" ;
6
6
import { BsFileEarmark , BsFolder , BsGithub } from "react-icons/bs" ;
7
7
import { marked } from "marked" ;
8
+ import hljs from "highlight.js" ;
9
+ import "highlight.js/styles/github-dark.css" ; // Import your preferred style
8
10
9
11
const Repository = ( ) => {
10
12
const [ data , setData ] = useState ( [ ] ) ;
@@ -102,6 +104,12 @@ const Repository = () => {
102
104
if ( pathname ) fetchData ( ) ;
103
105
} , [ pathname ] ) ;
104
106
107
+ useEffect ( ( ) => {
108
+ if ( fileContent ?. content ) {
109
+ hljs . highlightAll ( ) ; // Apply syntax highlighting to code blocks
110
+ }
111
+ } , [ fileContent ] ) ;
112
+
105
113
const handleItemClick = ( item ) => {
106
114
const newPath = `/devjourney/${ item . path } ` ;
107
115
router . push ( newPath ) ;
@@ -110,7 +118,7 @@ const Repository = () => {
110
118
const renderDirMap = ( ) => {
111
119
if ( loading ) return < p > Loading...</ p > ;
112
120
if ( error ) return < p > Error: { error } </ p > ;
113
- if ( data . length === 0 ) return null ; // Hide if empty
121
+ if ( data . length === 0 ) return null ;
114
122
115
123
return (
116
124
< ul className = { djStyles . dirMapContainer } >
@@ -126,25 +134,25 @@ const Repository = () => {
126
134
) ;
127
135
} ;
128
136
129
-
130
137
const renderContent = ( ) => {
131
138
if ( ! fileContent ) return null ;
132
139
133
140
return (
134
141
< div className = { djStyles . contentContainer } >
135
142
< h2 className = { djStyles . fileName } > { fileContent . name } </ h2 >
136
143
{ fileContent . name . endsWith ( ".md" ) ? (
137
- // Render markdown content
138
- < div className = { djStyles . markdownContent }
144
+ < div
145
+ className = { djStyles . markdownContent }
139
146
dangerouslySetInnerHTML = { { __html : marked ( fileContent . content ) } }
140
147
/>
141
148
) : (
142
- // Render plain text content
143
- < pre className = { djStyles . fileContent } >
144
- { fileContent . content }
149
+ < pre className = "hljs" >
150
+ { /* Removed djStyles.fileContent */ }
151
+ < code > { fileContent . content } </ code >
145
152
</ pre >
146
- ) }
147
- </ div >
153
+ )
154
+ }
155
+ </ div >
148
156
) ;
149
157
} ;
150
158
@@ -160,25 +168,15 @@ const Repository = () => {
160
168
161
169
return (
162
170
< div key = { path } className = { djStyles . breadcrumbHome } >
163
- < button
164
-
165
- onClick = { ( ) => router . push ( path ) }
166
- >
167
- { decodedSegment }
168
- </ button >
171
+ < button onClick = { ( ) => router . push ( path ) } > { decodedSegment } </ button >
169
172
{ index < pathSegments . length - 1 && " / " }
170
173
</ div >
171
174
) ;
172
175
} ) ;
173
176
174
177
return (
175
- < div className = { djStyles . breadcrumbContainer } id = 'breadcrumb' >
176
- < button
177
-
178
- onClick = { ( ) => router . push ( "/devjourney" ) }
179
- >
180
- Home
181
- </ button >
178
+ < div className = { djStyles . breadcrumbContainer } id = "breadcrumb" >
179
+ < button onClick = { ( ) => router . push ( "/devjourney" ) } > Home</ button >
182
180
{ breadcrumbItems . length > 0 && " / " }
183
181
{ breadcrumbItems }
184
182
</ div >
@@ -200,12 +198,11 @@ const Repository = () => {
200
198
} ;
201
199
202
200
return (
203
- < div className = { djStyles . devjourneyContainer } id = ' main' >
201
+ < div className = { djStyles . devjourneyContainer } id = " main" >
204
202
{ renderBreadcrumb ( ) }
205
203
{ renderGitHubButton ( ) }
206
204
{ renderContent ( ) }
207
205
{ renderDirMap ( ) }
208
-
209
206
</ div >
210
207
) ;
211
208
} ;
0 commit comments