@@ -803,53 +803,26 @@ <h2 class="text-3xl font-bold mb-6">Get Involved</h2>
803
803
'action' : 'OWASP-BLT/BLT-Action'
804
804
} ;
805
805
806
- // Cache star counts in localStorage with expiration
807
- function getStoredStarCount ( repo ) {
808
- const stored = localStorage . getItem ( `star_count_${ repo } ` ) ;
809
- if ( stored ) {
810
- try {
811
- const { count, timestamp } = JSON . parse ( stored ) ;
812
- // Cache for 1 hour
813
- if ( Date . now ( ) - timestamp < 3600000 ) {
814
- return count ;
815
- }
816
- } catch ( e ) {
817
- return null ;
818
- }
806
+ // Display star counts from the database
807
+ { % for repo in repo_stars % }
808
+ const countElement = document . getElementById ( `{{ repo.key }}-star-count` ) ;
809
+ if ( countElement ) {
810
+ countElement . textContent = { { repo . stars } } ;
819
811
}
812
+ { % endfor % }
820
813
821
- function storeStarCount ( repo , count ) {
822
- localStorage . setItem ( `star_count_${ repo } ` , JSON . stringify ( {
823
- count : count ,
824
- timestamp : Date . now ( )
825
- } ) ) ;
826
- }
827
-
814
+ // Fallback to GitHub API if no data in database
828
815
Object . entries ( repos ) . forEach ( ( [ key , repo ] ) => {
829
816
const countElement = document . getElementById ( `${ key } -star-count` ) ;
830
- if ( ! countElement ) return ;
831
-
832
- // First try to get from cache
833
- const cachedCount = getStoredStarCount ( repo ) ;
834
- if ( cachedCount !== null ) {
835
- countElement . textContent = cachedCount ;
836
- }
817
+ if ( ! countElement || countElement . textContent . trim ( ) !== '' ) return ;
837
818
838
- // Then fetch fresh data
819
+ // If we don't have data from the database, fetch from GitHub API
839
820
fetch ( `https://api.github.com/repos/${ repo } ` , {
840
821
headers : {
841
822
'Accept' : 'application/vnd.github.v3+json'
842
823
}
843
824
} )
844
825
. then ( response => {
845
- if ( response . status === 403 ) {
846
- // Rate limited - use cached value or keep showing loading
847
- const cached = getStoredStarCount ( repo ) ;
848
- if ( cached !== null ) {
849
- countElement . textContent = cached ;
850
- }
851
- throw new Error ( 'Rate limited' ) ;
852
- }
853
826
if ( ! response . ok ) {
854
827
throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
855
828
}
@@ -858,16 +831,11 @@ <h2 class="text-3xl font-bold mb-6">Get Involved</h2>
858
831
. then ( data => {
859
832
if ( data && typeof data . stargazers_count === 'number' ) {
860
833
countElement . textContent = data . stargazers_count ;
861
- storeStarCount ( repo , data . stargazers_count ) ;
862
834
}
863
835
} )
864
836
. catch ( error => {
865
837
console . error ( `Error fetching star count for ${ repo } :` , error ) ;
866
- // Only show 0 if we don't have a cached value
867
- const cached = getStoredStarCount ( repo ) ;
868
- if ( cached === null ) {
869
- countElement . textContent = '...' ;
870
- }
838
+ countElement . textContent = '...' ;
871
839
} ) ;
872
840
} ) ;
873
841
</ script >
0 commit comments