Skip to content

Commit

Permalink
fix: exported links typing
Browse files Browse the repository at this point in the history
  • Loading branch information
stafyniaksacha committed Mar 20, 2023
1 parent 6c14081 commit 07b6e11
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
3 changes: 2 additions & 1 deletion client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ declare module 'unfonts.css' {
}

declare module 'unplugin-fonts/head' {
export const links: string[]
import { HtmlTagDescriptor } from "vite"
export const links: HtmlTagDescriptor[]
}
16 changes: 10 additions & 6 deletions examples/astro/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
import Unfont from 'unplugin-fonts/astro/component.astro';
---

<div>
<Unfont />
<h1>Hello Astro!</h1>
<h2>I'm using a local font !</h2>
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
</div>
<html>
<head>
<Unfont />
</head>
<body>
<h1>Hello Astro!</h1>
<h2>I'm using a local font !</h2>
<a href="https://vitejs.dev/guide/features.html" target="_blank">Documentation</a>
</body>
</html>

<style>
body {
Expand Down
13 changes: 3 additions & 10 deletions src/astro.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import type { AstroIntegration } from 'astro'
import type { Options } from './types'
import unplugin from '.'
// import { getHeadLinkTags } from './loaders'

export default function (options: Options) {
return {
return <AstroIntegration>{
name: 'unplugin-fonts',
hooks: {
'astro:config:setup': async (astro: any) => {
'astro:config:setup': async (astro) => {
if (options?.custom)
options.custom.stripPrefix = 'public/'

astro.config.vite.plugins ||= []
astro.config.vite.plugins.push(unplugin.vite(options))

// const links = getHeadLinkTags(options, astro.config.root.toString())
// const linksString: string[] = []

// for (const link of links) {
// linksString.push(`<link ${Object.entries(link.attrs || {}).map(([key, value]) => `${key}="${value}"`).join(' ')} />`)
// }

astro.injectScript('page-ssr', 'import "unfonts.css";')
},
},
Expand Down
7 changes: 2 additions & 5 deletions src/astro/component.astro
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
---
import type { HtmlTagDescriptor } from 'vite'
// @ts-ignore
import { links } from 'unplugin-fonts/head'
---

<>
{links.map((link: HtmlTagDescriptor) => {
{links.map((link) => {
const attrs = link?.attrs || {}
return (
<link {...attrs} />
)
})}
</>
</>

0 comments on commit 07b6e11

Please sign in to comment.