Skip to content

Commit

Permalink
feat: add custom font transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
stafyniaksacha committed Mar 19, 2023
1 parent a31f167 commit 05e339a
Show file tree
Hide file tree
Showing 31 changed files with 1,060 additions and 365 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
*.snap
docs/.vitepress/cache
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.DS_Store
dist
dist
docs/.vitepress/cache
45 changes: 45 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { defineConfig } from 'vitepress'
import Unfonts from '../../src/vite'

export default defineConfig({
base: '/unplugin-fonts/',
// site-level options
title: 'VitePress',
description: 'Just playing around.',

themeConfig: {
// theme-level options
},

vite: {
plugins: [
Unfonts({
google: {
families: ['Crimson Pro', 'Open Sans', 'Material+Icons'],
},

custom: {
display: 'swap',
families: {
'Dancing Script': './public/assets/fonts/DancingScript*',
},
},

fontsource: {
families: [
{
name: 'ABeeZee',
weights: [400],
styles: ['italic'],
},
{
name: 'Truculenta',
weights: [400, 700],
subset: 'latin-ext',
},
],
},
}),
],
},
})
6 changes: 6 additions & 0 deletions docs/.vitepress/theme/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

:root {
/* --vp-font-family-base: "ABeeZee", sans-serif !important; */
/* --vp-font-family-base: "Crimson Pro", sans-serif !important; */
--vp-font-family-base: "Dancing Script", sans-serif !important;
}
6 changes: 6 additions & 0 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @ts-expect-error - not typed in vitepress 60
import DefaultTheme from 'vitepress/theme-without-fonts'
import './custom.css'
import 'unfonts.css'

export default DefaultTheme
23 changes: 23 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
layout: home

hero:
name: VitePress
text: Just playing around.
tagline: My great project tagline
actions:
- theme: brand
text: Markdown Examples
link: /markdown-examples
- theme: alt
text: API Examples
link: /api-examples

features:
- title: Feature A
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature B
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature C
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
---
15 changes: 15 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "docs",
"private": true,
"scripts": {
"dev": "vitepress dev",
"start": "vitepress dev",
"build": "vitepress build",
"preview": "vitepress preview"
},
"devDependencies": {
"unplugin-fonts": "workspace:*",
"vitepress": "^1.0.0-alpha.60"
}

}
Binary file added docs/public/assets/fonts/DancingScript-Bold.ttf
Binary file not shown.
Binary file added docs/public/assets/fonts/DancingScript-Medium.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export default defineNuxtConfig({
'Dancing Script': './assets/fonts/DancingScript*',
},
},
}
},
})
2 changes: 1 addition & 1 deletion examples/nuxt/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
}
6 changes: 3 additions & 3 deletions examples/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"preview": "vite preview"
},
"devDependencies": {
"vite": "^4.2.0",
"unplugin-fonts": "workspace:*",
"@fontsource/abeezee": "^4.5.10",
"@fontsource/truculenta": "^4.5.12"
"@fontsource/truculenta": "^4.5.12",
"unplugin-fonts": "workspace:*",
"vite": "^4.2.0"
}
}
10 changes: 9 additions & 1 deletion examples/vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ export default defineConfig({
custom: {
display: 'swap',
families: {
'Dancing Script': './assets/fonts/DancingScript*',
'Dancing Script': {
src: './assets/fonts/DancingScript*',
transform(font) {
if (font.basename === 'DancingScript-Bold')
font.weight = 700

return font
},
},
},
},

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@
"build:fix": "esno scripts/postbuild.ts",
"example:dev": "npm -C examples/vite run dev",
"example:build": "npm -C examples/vite run build",
"docs:dev": "npm -C docs run dev",
"docs:build": "npm -C docs run build",
"lint": "eslint .",
"lint:fix": "eslint --fix ."
"lint:fix": "eslint --fix .",
"test": "vitest"
},
"peerDependencies": {
"@nuxt/kit": "^3.0.0",
Expand All @@ -97,6 +100,7 @@
"@types/node": "^18.15.3",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"chalk": "^5.2.0",
"defu": "^6.1.2",
"eslint": "^8.36.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"esno": "^0.16.3",
Expand All @@ -105,6 +109,7 @@
"tsup": "^6.6.3",
"typescript": "^5.0.2",
"vite": "^4.2.0",
"vitest": "^0.29.3",
"webpack": "^5.76.2"
}
}
Loading

0 comments on commit 05e339a

Please sign in to comment.