Skip to content

Commit

Permalink
feat: upgrade posthtml
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Apr 20, 2024
1 parent b182f61 commit bb79791
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dependencies": {
"datauri": "^4.1.0",
"posthtml": "^0.12.0"
"posthtml": "^0.16.6"
},
"devDependencies": {
"@types/jest": "^29.5.12",
Expand Down
16 changes: 8 additions & 8 deletions src/inlineFavicon.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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;
},
Expand Down

0 comments on commit bb79791

Please sign in to comment.