@@ -38,16 +38,31 @@ function createLanguageBar(languages) {
3838async function fetchLanguages ( repo ) {
3939 if ( langCache . has ( repo ) ) return langCache . get ( repo ) ;
4040
41- const url = `https://api.github.com/repos/${ repo } /languages` ;
42- const resp = await fetch ( url ) ;
43-
44- if ( ! resp . ok ) {
45- console . warn ( `Could not load languages for ${ repo } : ${ resp . status } ` ) ;
46- langCache . set ( repo , { } ) ;
47- return { } ;
41+ const ghurl = `https://api.github.com/repos/${ repo } /languages` ;
42+ let data = { } ;
43+
44+ try {
45+ const resp = await fetch ( ghurl ) ;
46+ if ( ! resp . ok ) throw new Error ( `GitHub API error: ${ resp . status } ` ) ;
47+ data = await resp . json ( ) ;
48+ } catch ( err ) {
49+ console . warn ( `Could not load languages for ${ repo } from GitHub (Private repo), trying local fallback` , err ) ;
50+ const repoName = repo . includes ( '/' ) ? repo . split ( '/' ) [ 1 ] : repo ;
51+ const fallbackFile = `/projects/languages/${ repoName } .json` ;
52+ try {
53+ const r2 = await fetch ( fallbackFile ) ;
54+ if ( r2 . ok ) {
55+ data = await r2 . json ( ) ;
56+ } else {
57+ console . warn ( `Local fallback file not found: ${ fallbackFile } ` ) ;
58+ return { } ;
59+ }
60+ } catch ( e2 ) {
61+ console . error ( `Error loading local fallback for ${ repo } :` , e2 ) ;
62+ data = { } ;
63+ }
4864 }
4965
50- const data = await resp . json ( ) ;
5166 langCache . set ( repo , data ) ;
5267 return data ;
5368}
@@ -84,7 +99,7 @@ fetch("projects/metadata.json")
8499 // short description under the title
85100 if ( project . description ) {
86101 const desc = document . createElement ( "p" ) ;
87- desc . className = "project-description" ;
102+ desc . className = "project-description" ;
88103 desc . textContent = project . description ;
89104 info . appendChild ( desc ) ;
90105 }
@@ -96,7 +111,7 @@ fetch("projects/metadata.json")
96111
97112 //header
98113 const techLabel = document . createElement ( "div" ) ;
99- techLabel . className = "languages-label" ;
114+ techLabel . className = "languages-label" ;
100115 techLabel . textContent = "languages" ;
101116 techContainer . appendChild ( techLabel ) ;
102117
@@ -112,24 +127,24 @@ fetch("projects/metadata.json")
112127 if ( project . repo ) {
113128 try {
114129 const languages = await fetchLanguages ( project . repo ) ;
115- const total = Object . values ( languages ) . reduce ( ( a , b ) => a + b , 0 ) ;
130+ const total = Object . values ( languages ) . reduce ( ( a , b ) => a + b , 0 ) ;
116131
117132 const languageBar = createLanguageBar ( languages ) ;
118133 wrapper . appendChild ( languageBar ) ;
119134
120135 const langList = document . createElement ( "div" ) ;
121136 langList . className = "linguist-langs" ;
122137 Object . entries ( languages ) . forEach ( ( [ lang , bytes ] ) => {
123- const pct = total
124- ? ( ( bytes / total * 100 ) . toFixed ( 1 ) + "%" )
138+ const pct = total
139+ ? ( ( bytes / total * 100 ) . toFixed ( 1 ) + "%" )
125140 : "0%" ;
126141 const line = document . createElement ( "div" ) ;
127142 line . textContent = `${ lang } – ${ pct } ` ;
128143 langList . appendChild ( line ) ;
129144 } ) ;
130145 wrapper . appendChild ( langList ) ;
131146
132- } catch ( err ) {
147+ } catch ( err ) {
133148 console . error ( `Could not load languages for ${ project . repo } ` , err ) ;
134149 }
135150 }
0 commit comments