Skip to content

Commit

Permalink
feat: support custom webfonts
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 6, 2021
1 parent 8bb65a9 commit d4c5bad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/parser/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ function resolveFonts(fonts: FontOptions = {}): ResolvedFontOptions {
let sans = toArray(fonts.sans).flatMap(i => i.split(/,\s*/g)).map(i => i.trim())
let serif = toArray(fonts.serif).flatMap(i => i.split(/,\s*/g)).map(i => i.trim())
let mono = toArray(fonts.mono).flatMap(i => i.split(/,\s*/g)).map(i => i.trim())
const custom = toArray(fonts.custom).flatMap(i => i.split(/,\s*/g)).map(i => i.trim())

const local = toArray(fonts.local).flatMap(i => i.split(/,\s*/g)).map(i => i.trim())
const webfonts = fonts.webfonts
? fonts.webfonts
: fallbacks
? uniq([...sans, ...serif, ...mono])
? uniq([...sans, ...serif, ...mono, ...custom])
: []

webfonts.filter(i => local.includes(i))
Expand Down
16 changes: 15 additions & 1 deletion packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,23 @@ export interface SlidevThemeMeta {
export type SlidevThemeConfig = Record<string, string | number>

export type FontOptions = {
/**
* Sans serif fonts (default fonts for most text)
*/
sans?: string | string[]
mono?: string | string[]
/**
* Serif fonts
*/
serif?: string | string[]
/**
* Monospace fonts, for code blocks and etc.
*/
mono?: string | string[]
/**
* Load webfonts for custom CSS (does not apply anywhere by default)
*/
custom?: string | string[]

/**
* @default 'google'
*/
Expand Down

0 comments on commit d4c5bad

Please sign in to comment.