@@ -19,6 +19,44 @@ async function fetchBadgeData(repo, badgeFile) {
1919 }
2020}
2121
22+ async function fetchVariantsData ( repo ) {
23+ try {
24+ const url = `https://raw.githubusercontent.com/giellalt/${ repo . name } /main/docs/badgedata/fst-variants.json` ;
25+ const response = await fetch ( url ) ;
26+ if ( ! response . ok ) {
27+ return null ;
28+ }
29+ const data = await response . json ( ) ;
30+
31+ // Extract all variants with has_speller: true
32+ const variants = [ ] ;
33+ const categories = [ 'dialects' , 'areas' , 'orthographies' , 'writing_systems' ] ;
34+ const categoryMap = {
35+ 'dialects' : 'dialect' ,
36+ 'areas' : 'area' ,
37+ 'orthographies' : 'orthography' ,
38+ 'writing_systems' : 'writing-system'
39+ } ;
40+
41+ for ( const category of categories ) {
42+ if ( data [ category ] && Array . isArray ( data [ category ] ) ) {
43+ for ( const variant of data [ category ] ) {
44+ if ( variant . has_speller === true ) {
45+ variants . push ( {
46+ category : categoryMap [ category ] ,
47+ code : variant . code
48+ } ) ;
49+ }
50+ }
51+ }
52+ }
53+
54+ return variants . length > 0 ? variants : null ;
55+ } catch ( error ) {
56+ return null ;
57+ }
58+ }
59+
2260function parseVersion ( versionString ) {
2361 if ( ! versionString ) return null ;
2462 // Remove 'v' prefix if present, extract version number
@@ -194,7 +232,7 @@ function addSpellerTableHeader() {
194232 return row_1 ;
195233}
196234
197- function addSpellerRepoTable ( repos , mainFilter , filters ) {
235+ async function addSpellerRepoTable ( repos , mainFilter , filters ) {
198236 let table = document . createElement ( 'table' ) ;
199237 let thead = document . createElement ( 'thead' ) ;
200238 let tbody = document . createElement ( 'tbody' ) ;
@@ -223,10 +261,12 @@ function addSpellerRepoTable(repos, mainFilter, filters) {
223261 for ( const repo of repos ) {
224262 if ( repo . name . startsWith ( mainFilter ) ) {
225263 if ( filters === null || filters . length === 0 ) {
226- tbody . appendChild ( addSpellerTR ( repo ) ) ;
264+ const row = await addSpellerTR ( repo ) ;
265+ tbody . appendChild ( row ) ;
227266 } else {
228267 if ( doesTopicsHaveSomeFilter ( repo . topics , filters ) ) {
229- tbody . appendChild ( addSpellerTR ( repo ) ) ;
268+ const row = await addSpellerTR ( repo ) ;
269+ tbody . appendChild ( row ) ;
230270 }
231271 }
232272 }
@@ -252,22 +292,62 @@ function addSpellerVersion(repo) {
252292 return row_version ;
253293}
254294
255- function addSpellerSuggQuality ( repo ) {
295+ async function addSpellerSuggQuality ( repo ) {
256296 let row_sugg = document . createElement ( 'td' ) ;
257- const sugg_link = document . createElement ( 'a' ) ;
258- sugg_link . setAttribute ( 'href' , '/' + repo . name + '/typosreport/' ) ;
259- const sugg_image = document . createElement ( 'img' ) ;
260- sugg_image . setAttribute (
261- 'src' ,
262- 'https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fgiellalt%2F' + repo . name + '%2Fmain%2Fdocs%2Fbadgedata%2Fspeller-suggestions.json&label=S'
263- ) ;
264- sugg_image . setAttribute ( 'alt' , 'Suggestion Quality' ) ;
265- sugg_link . appendChild ( sugg_image ) ;
266- row_sugg . appendChild ( sugg_link ) ;
297+
298+ // First, try to fetch variants data
299+ const variantsData = await fetchVariantsData ( repo ) ;
300+
301+ // If no variants or all null, show default badge
302+ if ( ! variantsData || variantsData . length === 0 ) {
303+ const sugg_link = document . createElement ( 'a' ) ;
304+ sugg_link . setAttribute ( 'href' , '/' + repo . name + '/typosreport/' ) ;
305+ const sugg_image = document . createElement ( 'img' ) ;
306+ sugg_image . setAttribute (
307+ 'src' ,
308+ 'https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fgiellalt%2F' + repo . name + '%2Fmain%2Fdocs%2Fbadgedata%2Fspeller-suggestions.json&label=S'
309+ ) ;
310+ sugg_image . setAttribute ( 'alt' , 'Suggestion Quality' ) ;
311+ sugg_link . appendChild ( sugg_image ) ;
312+ row_sugg . appendChild ( sugg_link ) ;
313+ } else {
314+ // Add default badge first
315+ const default_link = document . createElement ( 'a' ) ;
316+ default_link . setAttribute ( 'href' , '/' + repo . name + '/typosreport/' ) ;
317+ const default_image = document . createElement ( 'img' ) ;
318+ default_image . setAttribute (
319+ 'src' ,
320+ 'https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fgiellalt%2F' + repo . name + '%2Fmain%2Fdocs%2Fbadgedata%2Fspeller-suggestions.json&label=S'
321+ ) ;
322+ default_image . setAttribute ( 'alt' , 'Suggestion Quality' ) ;
323+ default_link . appendChild ( default_image ) ;
324+ row_sugg . appendChild ( default_link ) ;
325+ row_sugg . appendChild ( document . createElement ( 'br' ) ) ;
326+
327+ // Add variant badges
328+ for ( let i = 0 ; i < variantsData . length ; i ++ ) {
329+ const variant = variantsData [ i ] ;
330+ const variant_link = document . createElement ( 'a' ) ;
331+ variant_link . setAttribute ( 'href' , '/' + repo . name + '/typosreport/' ) ;
332+ const variant_image = document . createElement ( 'img' ) ;
333+ const variantFile = `speller-suggestions-${ variant . code } .json` ;
334+ variant_image . setAttribute (
335+ 'src' ,
336+ 'https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fgiellalt%2F' + repo . name + '%2Fmain%2Fdocs%2Fbadgedata%2F' + encodeURIComponent ( variantFile ) + '&label=' + encodeURIComponent ( 'S-' + variant . code )
337+ ) ;
338+ variant_image . setAttribute ( 'alt' , `Suggestion Quality: ${ variant . category } -${ variant . code } ` ) ;
339+ variant_link . appendChild ( variant_image ) ;
340+ row_sugg . appendChild ( variant_link ) ;
341+ if ( i < variantsData . length - 1 ) {
342+ row_sugg . appendChild ( document . createElement ( 'br' ) ) ;
343+ }
344+ }
345+ }
346+
267347 return row_sugg ;
268348}
269349
270- function addSpellerTR ( repo ) {
350+ async function addSpellerTR ( repo ) {
271351 let row = document . createElement ( 'tr' ) ;
272352
273353 let row_lang = document . createElement ( 'td' ) ;
@@ -277,7 +357,7 @@ function addSpellerTR(repo) {
277357 row . appendChild ( addRepo ( repo ) ) ;
278358 row . appendChild ( addSpellerVersion ( repo ) ) ;
279359 row . appendChild ( addLemmaCount ( repo ) ) ;
280- row . appendChild ( addSpellerSuggQuality ( repo ) ) ;
360+ row . appendChild ( await addSpellerSuggQuality ( repo ) ) ;
281361
282362 return row ;
283363}
@@ -326,9 +406,10 @@ async function addSpellerRepoTableByMaturity(repos, mainFilter, maturityLevel) {
326406 . filter ( item => item . maturity === maturityLevel )
327407 . map ( item => item . repo ) ;
328408
329- // Add rows to table
409+ // Add rows to table (async)
330410 for ( const repo of filteredRepos ) {
331- tbody . appendChild ( addSpellerTR ( repo ) ) ;
411+ const row = await addSpellerTR ( repo ) ;
412+ tbody . appendChild ( row ) ;
332413 }
333414
334415 // If no repos found, inform the user:
0 commit comments