Skip to content
This repository was archived by the owner on Nov 14, 2024. It is now read-only.

Commit e5883c4

Browse files
committed
update vitepress theme for sponsor externalization part 3
1 parent 6bb3b98 commit e5883c4

File tree

3 files changed

+147
-110
lines changed

3 files changed

+147
-110
lines changed

index.md

+30-15
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,44 @@ footer: Copyright ©2024 Kalabox Inc.
109109
</div>
110110

111111
<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';
117114

118115
import {VPButton} from 'vitepress/theme';
119116
import {VPHomeHero} from 'vitepress/theme';
120117
import {VPHomeFeatures} from 'vitepress/theme';
121118
import {VPSponsors} from 'vitepress/theme';
122119
import {useData} from 'vitepress';
123120

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+
};
133127

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+
});
135150

136151
</script>
137152

0 commit comments

Comments
 (0)