@@ -109,29 +109,44 @@ footer: Copyright ©2024 Kalabox Inc.
109
109
</div >
110
110
111
111
<script setup >
112
- const getSponsorTier = (sponsors , tier = ' patriot' ) => {
113
- return sponsors
114
- .filter (sponsor => sponsor .tier === tier)
115
- .map (({name, logo, url}) => ({name, url, img: logo}));
116
- };
112
+ import yaml from ' js-yaml' ;
113
+ import {computed , onMounted , ref } from ' vue' ;
117
114
118
115
import {VPButton } from ' vitepress/theme' ;
119
116
import {VPHomeHero } from ' vitepress/theme' ;
120
117
import {VPHomeFeatures } from ' vitepress/theme' ;
121
118
import {VPSponsors } from ' vitepress/theme' ;
122
119
import {useData } from ' vitepress' ;
123
120
124
- const start = 1707233398000 ;
125
- const {frontmatter , theme } = useData ();
126
- const sponsors = theme .value ? .sponsors ? .all ?? [];
127
-
128
- const allies = getSponsorTier (sponsors, ' ally' );
129
- const patriots = getSponsorTier (sponsors, ' patriot' );
130
- const heralds = getSponsorTier (sponsors, ' herald' );
131
-
132
- const all = patriots .concat (allies);
121
+ const getSponsorTier = (sponsors , tier = ' patriot' ) => {
122
+ if (! Array .isArray (sponsors)) return [];
123
+ return sponsors
124
+ .filter (sponsor => sponsor .tier === tier)
125
+ .map (({name, logo, url}) => ({name, url, img: logo}));
126
+ };
133
127
134
- const heraldcompute = parseInt (heralds .length + (Date .now () - start) / 604800000 );
128
+ const start = 1707233398000 ;
129
+ const sponsors = ref (undefined );
130
+ const allies = computed (() => getSponsorTier (sponsors .value , ' ally' ));
131
+ const patriots = computed (() => getSponsorTier (sponsors .value , ' patriot' ));
132
+ const heralds = computed (() => getSponsorTier (sponsors .value , ' herald' ));
133
+ const all = computed (() => patriots .value .concat (allies .value ));
134
+
135
+ const heraldcompute = computed (() => parseInt (heralds .value .length + (Date .now () - start) / 604800000 ));
136
+
137
+ // if data is a string/needs to be fetched then do that here
138
+ onMounted (async () => {
139
+ // if data is already an array then we good
140
+ if (Array .isArray (sponsors .value )) return ;
141
+
142
+ try {
143
+ const response = await fetch (' https://raw.githubusercontent.com/lando/lando/main/sponsors.yaml' );
144
+ sponsors .value = yaml .load (await response .text ());
145
+ } catch (error) {
146
+ console .error (` could not fetch and parse data from ${ data .value } ` );
147
+ console .error (error);
148
+ }
149
+ });
135
150
136
151
</script >
137
152
0 commit comments