Skip to content

Commit

Permalink
fix: use svgo to remove self-closing tags (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter committed Apr 19, 2024
1 parent 7f91a66 commit f392220
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@humanfs/types": "0.13.0",
"jiti": "1.21.0",
"prettier": "3.2.5",
"svgo": "3.2.0",
"wxt": "0.17.3"
},
"scripts": {
Expand Down
58 changes: 58 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions wxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'wxt';

import { hfs } from '@humanfs/node';
import { join } from 'path';
import { optimize } from 'svgo';

import jiti from 'jiti';

Expand All @@ -27,13 +28,17 @@ export default defineConfig({
icons[entry.name.replace('.svg', '')] = await hfs
.text(join(ICON_DIR, entry.name))
.then((text) => {
const lines = text.split('\n');
return lines
.slice(1, lines.length - 2)
.join('\n')
.trim()
.replaceAll('--vscode-ctp', '--ctp')
.replaceAll('/>', '></path>');
return optimize(
text.replaceAll('--vscode-ctp', '--ctp'),
{
js2svg: { useShortTags: false },
},
)
.data.replace(
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">',
'',
)
.replace('</svg>', '');
});
}

Expand Down

0 comments on commit f392220

Please sign in to comment.