11import getIndicators from "./getIndicators.js" ;
2+ import summaryData from "$lib/data/json-stat-summary.json" ;
23import { capitalise } from "$lib/utils.ts" ;
34
45function makeItem ( slug , label = null , description = null ) {
5- const item = { label : label || capitalise ( slug ) , slug} ;
6- if ( description ) return { ...item , description} ;
7- return { ...item , children : { } } ;
6+ const item = { label : label || capitalise ( slug ) , slug } ;
7+ if ( description ) return { ...item , description } ;
8+ return { ...item , children : { } } ;
89}
910
1011function nestTaxonomy ( taxonomy ) {
@@ -18,21 +19,25 @@ function nestTaxonomy(taxonomy) {
1819 } else {
1920 if ( ! topicsIndex [ ind . topic ] . children [ ind . subTopic ] )
2021 topicsIndex [ ind . topic ] . children [ ind . subTopic ] = makeItem ( ind . subTopic ) ;
21- topicsIndex [ ind . topic ] . children [ ind . subTopic ] . children [ ind . slug ] = indicator ;
22+ topicsIndex [ ind . topic ] . children [ ind . subTopic ] . children [ ind . slug ] =
23+ indicator ;
2224 }
2325 }
2426
2527 const topics = Object . values ( topicsIndex ) ;
2628 for ( const topic of topics ) {
2729 topic . children = Object . values ( topic . children ) ;
2830 if ( topic . children [ 0 ] . children ) {
29- for ( const subTopic of topic . children ) subTopic . children = Object . values ( subTopic . children ) ;
31+ for ( const subTopic of topic . children )
32+ subTopic . children = Object . values ( subTopic . children ) ;
3033 }
3134 }
3235 return topics ;
3336}
3437
3538export default function getTaxonomy ( params = { } ) {
36- const taxonomy = getIndicators ( { ...params , minimalMetadata : true } ) ;
37- return params . flat ? taxonomy : nestTaxonomy ( taxonomy ) ;
39+ const taxonomy = getIndicators ( { ...params , minimalMetadata : true } ) ;
40+ const meta = { count : taxonomy . length , total : summaryData . count } ;
41+ const data = params . flat ? taxonomy : nestTaxonomy ( taxonomy ) ;
42+ return { meta, data } ;
3843}
0 commit comments