diff --git a/bun.lockb b/bun.lockb index bf045c4..27acb1c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 41d0704..b1ef8f6 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "datauri": "^4.1.0", - "posthtml": "^0.12.0" + "posthtml": "^0.16.6" }, "devDependencies": { "@types/jest": "^29.5.12", diff --git a/src/inlineFavicon.ts b/src/inlineFavicon.ts index 245dbca..246b667 100644 --- a/src/inlineFavicon.ts +++ b/src/inlineFavicon.ts @@ -1,23 +1,23 @@ import Datauri from "datauri/sync"; -import path from "path"; -import { PostHTML } from "posthtml"; +import path from "node:path"; +import { type Plugin } from "posthtml"; -function inlineFavicon(options: IOptions = { path: "" }) { - return function plugin(tree: PostHTML.Node) { +function inlineFavicon(options: IOptions = { path: "" }): Plugin { + return function plugin(tree) { tree.match( { tag: "link", attrs: { rel: new RegExp(/icon/), href: new RegExp(/\S+/) }, }, (node) => { - const href = node.attrs!.href as string; + const href = node.attrs.href; const file = path.join(process.cwd(), options.path || "", href); const { base64 } = Datauri(file); - node.attrs!.rel = "icon"; - node.attrs!.type = "image/png"; - node.attrs!.href = `data:image/png;base64,${base64}`; + node.attrs.rel = "icon"; + node.attrs.type = "image/png"; + node.attrs.href = `data:image/png;base64,${base64}`; return node; },