Skip to content

Commit

Permalink
refactor(google): split out api client
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 20, 2024
1 parent f5011c9 commit dbd736a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/providers/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ interface FontDetail extends Omit<FontIndexMeta, 'variants'> {
fontFamily: string
fontStyle: string
fontWeight: string
//
eot: string
woff: string
ttf: string
Expand All @@ -33,20 +32,25 @@ interface FontDetail extends Omit<FontIndexMeta, 'variants'> {
storeID: string
}

const fontAPI = $fetch.create({
baseURL: 'https://gwfh.mranftl.com/api/fonts'
})

let fonts: Array<FontIndexMeta>
let fonts: FontIndexMeta[]
export default {
async setup () {
// TODO: Fetch and cache possible Google fonts
fonts = await $fetch('https://gwfh.mranftl.com/api/fonts')
fonts = await fontAPI<FontIndexMeta[]>('/')
},
async resolveFontFaces (fontFamily, defaults) {
const font = fonts.find(font => font.family === fontFamily)
if (!font) { return }

const subsets = defaults.subsets.filter(subset => font.subsets.includes(subset))

const details = await $fetch<FontDetail>(`https://gwfh.mranftl.com/api/fonts/${font.id}?subsets=${subsets.join(',')}`)
const details = await fontAPI<FontDetail>(font.id, {
query: subsets.length ? { subsets: subsets.join(',') } : {}
})

return {
fonts: details.variants.map(variant => ({
Expand All @@ -66,3 +70,4 @@ export default {
}
},
} satisfies FontProvider

0 comments on commit dbd736a

Please sign in to comment.