Skip to content

Commit

Permalink
fix(nuxt3): use web fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
LarchLiu committed May 17, 2023
1 parent 38c2eee commit f693dfb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
12 changes: 6 additions & 6 deletions server/nuxt3/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export default defineNuxtConfig({
// baseName: 'fonts',
// dir: './assets/fonts', // Relative to `srcDir` (`server/` for nuxt)
// }],
storage: {
fs: {
driver: 'fs',
base: './server/assets/fonts',
},
},
// storage: {
// fs: {
// driver: 'fs',
// base: './server/assets/fonts',
// },
// },
esbuild: {
options: {
target: 'esnext',
Expand Down
22 changes: 10 additions & 12 deletions server/nuxt3/server/utils/webCard/font.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { join, resolve } from 'node:path'
import { promises as fsPromises } from 'node:fs'
import { $fetch } from 'ofetch'
import type { SatoriOptions } from 'satori'
import type { apis } from './twemoji'
Expand Down Expand Up @@ -315,20 +313,20 @@ export async function initBasicFonts() {
return basicFonts

// https://unpkg.com/browse/@fontsource/inter@4.5.2/files/
// const interRegular = await $fetch('https://unpkg.com/@fontsource/inter@4.5.2/files/inter-all-400-normal.woff', { responseType: 'arrayBuffer' })
// const InterBold = await $fetch('https://unpkg.com/@fontsource/inter@4.5.2/files/inter-all-700-normal.woff', { responseType: 'arrayBuffer' })
const InterRegular = await $fetch('https://unpkg.com/@fontsource/inter@4.5.2/files/inter-all-400-normal.woff', { responseType: 'arrayBuffer' })
const InterBold = await $fetch('https://unpkg.com/@fontsource/inter@4.5.2/files/inter-all-700-normal.woff', { responseType: 'arrayBuffer' })
// const notoScRegular = await $fetch('https://unpkg.com/@fontsource/noto-sans-sc@4.5.12/files/noto-sans-sc-chinese-simplified-400-normal.woff', { responseType: 'arrayBuffer' })
const base = resolve('./server/assets/fonts')
const r = (key: string) => {
const resolved = join(resolve(base), key)
return resolved
}
// const InterRegular = await useStorage('fs').getItemRaw('Inter-Regular.ttf')
// const base = resolve('./server/assets/fonts')
// const r = (key: string) => {
// const resolved = join(resolve(base), key)
// return resolved
// }
// const InterRegular = await useStorage('assets:fonts').getItemRaw('Inter-Regular.ttf')
// const InterBold = await useStorage('fs').getItemRaw('test.json')
// const NotoSansSC = await useStorage('assets:fonts').getItem('NotoSansSC-Regular.otf')

const InterRegular = await fsPromises.readFile(r('Inter-Regular.ttf'))
const InterBold = await fsPromises.readFile(r('Inter-Bold.ttf'))
// const InterRegular = await fsPromises.readFile(r('Inter-Regular.ttf'))
// const InterBold = await fsPromises.readFile(r('Inter-Bold.ttf'))
// const NotoSansSC = await fsPromises.readFile(r('NotoSansSC-Regular.otf'))
// const NotoEmoji = await fsPromises.readFile(r('NotoColorEmoji-Regular.ttf'))

Expand Down

1 comment on commit f693dfb

@vercel
Copy link

@vercel vercel bot commented on f693dfb May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

star-nexus – ./

star-nexus-larchliu.vercel.app
star-nexus-git-main-larchliu.vercel.app
star-nexus.vercel.app

Please sign in to comment.