From 17223dab762664f856ef2a53a19c275c771aebd9 Mon Sep 17 00:00:00 2001 From: SpotlightOn <265342703+SpotlightOn@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:05:24 +0100 Subject: [PATCH] Add husky and fix linter errors --- .github/workflows/codeql.yml | 2 +- .husky/pre-commit | 1 + README.md | 2 +- biome.jsonc | 2 +- package.json | 8 +- pnpm-lock.yaml | 39 +++- src/content/blog/custom-icon-sets/index.md | 46 ++--- src/content/blog/defs-vs-symbol-sprites.md | 66 +++---- src/content/blog/optimizing-svg-files.md | 212 +++++++++++---------- src/content/blog/svg-intro.md | 22 ++- src/content/blog/welcome.md | 8 +- 11 files changed, 225 insertions(+), 183 deletions(-) create mode 100644 .husky/pre-commit diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5d06a77..a6bc437 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -37,4 +37,4 @@ jobs: uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL analysis - uses: github/codeql-action/analyze@v3 \ No newline at end of file + uses: github/codeql-action/analyze@v3 diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..5ee7abd --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +pnpm exec lint-staged diff --git a/README.md b/README.md index 4f606be..47a32b2 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,4 @@ pnpm preview # preview the static build Any push to `main` triggers `.github/workflows/deploy.yml`, which builds the static site and deploys it to GitHub Pages (source: GitHub Actions). -The site is served at . \ No newline at end of file +The site is served at . diff --git a/biome.jsonc b/biome.jsonc index 6502136..7f9725f 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/2.5.13/schema.json", + "$schema": "https://biomejs.dev/schemas/2.6.4/schema.json", "vcs": { "enabled": true, "clientKind": "git", diff --git a/package.json b/package.json index 885327c..9f01d3b 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "check": "astro check", "lint": "biome ci .", "preview": "astro preview", - "astro": "astro" + "astro": "astro", + "prepare": "husky" }, "dependencies": { "@astrojs/sitemap": "^3.7.4", @@ -25,6 +26,11 @@ "devDependencies": { "@astrojs/check": "^0.9.12", "@biomejs/biome": "^2.6.4", + "husky": "^9.1.7", + "lint-staged": "^17.6.0", "typescript": "^6.0.3" + }, + "lint-staged": { + "*": "biome check --write --no-errors-on-unmatched --files-ignore-unknown=true" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e26ec2b..f8d0c94 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,6 +24,12 @@ importers: '@biomejs/biome': specifier: ^2.6.4 version: 2.6.4 + husky: + specifier: ^9.1.7 + version: 9.1.7 + lint-staged: + specifier: ^17.6.0 + version: 17.6.0 typescript: specifier: ^6.0.3 version: 6.0.3 @@ -1141,6 +1147,11 @@ packages: http-cache-semantics@4.3.0: resolution: {integrity: sha512-M5t5LlJpS1UHMjvwRQVdFHvPISGeLAxNcrWuJkeGh0KxsqCHZ1O3NXZU/8x7cD0BDcGW8kapxMKTvwlqrNkHkA==} + husky@9.1.7: + resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==} + engines: {node: '>=18'} + hasBin: true + iron-webcrypto@1.2.1: resolution: {integrity: sha512-feOM6FaSr6rEABp/eDfVseKyTMDt+KGpeB35SkVn9Tyn0CqvVsY3EwI0v5i8nMHyJnzCIQf7nsy3p41TPkJZhg==} @@ -1240,6 +1251,11 @@ packages: resolution: {integrity: sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==} engines: {node: '>= 12.0.0'} + lint-staged@17.6.0: + resolution: {integrity: sha512-nOhBfYkZEwkFtNzD5pK9s9LkcWoxJ+whLzEnhqi9nl7zTB5n7tg8+9iYgMGx2Wm3VlLu8cbNj0RACzY+nWi5iQ==} + engines: {node: '>=22.22.1'} + hasBin: true + lru-cache@11.5.3: resolution: {integrity: sha512-U4N8FgzmWxc8k1VH8Kr6lQg18U7Fjvby6wXHVRX/ZZ7IwWbRMgrRbP0Wrb5q5NVinryp4SQampHKdvtecItxUg==} engines: {node: 20 || >=22} @@ -1455,6 +1471,10 @@ packages: std-env@4.3.0: resolution: {integrity: sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==} + string-argv@0.3.2: + resolution: {integrity: sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==} + engines: {node: '>=0.6.19'} + string-width@7.2.0: resolution: {integrity: sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==} engines: {node: '>=18'} @@ -1499,9 +1519,6 @@ packages: trough@2.2.0: resolution: {integrity: sha512-tmMpK00BjZiUyVyvrBK7knerNgmgvcV/KLVyuma/SC+TQN167GrMRciANTz09+k3zW8L8t60jWO1GpfkZdjTaw==} - tslib@2.8.1: - resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} - tslib@2.9.1: resolution: {integrity: sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==} @@ -2106,7 +2123,7 @@ snapshots: '@emnapi/runtime@1.11.3': dependencies: - tslib: 2.8.1 + tslib: 2.9.1 '@emnapi/wasi-threads@1.2.2': dependencies: @@ -2852,6 +2869,8 @@ snapshots: http-cache-semantics@4.3.0: {} + husky@9.1.7: {} + iron-webcrypto@1.2.1: {} is-docker@4.0.0: {} @@ -2915,6 +2934,14 @@ snapshots: lightningcss-win32-arm64-msvc: 1.33.0 lightningcss-win32-x64-msvc: 1.33.0 + lint-staged@17.6.0: + dependencies: + picomatch: 4.0.7 + string-argv: 0.3.2 + tinyexec: 1.3.1 + optionalDependencies: + yaml: 2.9.1 + lru-cache@11.5.3: {} magic-string@1.4.5: @@ -3166,6 +3193,8 @@ snapshots: std-env@4.3.0: {} + string-argv@0.3.2: {} + string-width@7.2.0: dependencies: emoji-regex: 10.6.0 @@ -3213,8 +3242,6 @@ snapshots: trough@2.2.0: {} - tslib@2.8.1: {} - tslib@2.9.1: {} typesafe-path@0.2.2: {} diff --git a/src/content/blog/custom-icon-sets/index.md b/src/content/blog/custom-icon-sets/index.md index 1c5fdb5..68907f0 100644 --- a/src/content/blog/custom-icon-sets/index.md +++ b/src/content/blog/custom-icon-sets/index.md @@ -1,12 +1,14 @@ --- + title: Create Your Own Icon Sets for the SVG Forge Icon Manager pubDate: 2026-09-15 tags: - - tips - - svg +- tips +- svg + --- -The **SVG Forge Icon Manager** is a Gutenberg plugin for WordPress: an "SVG Icon" block inserts icons via `` from a central SVG sprite file into your content. The plugin is deliberately *not* an icon collection with an import UI — every icon must exist as a `` element in a sprite file that you build, maintain, and version yourself. +The **SVG Forge Icon Manager** is a Gutenberg plugin for WordPress: an "SVG Icon" block inserts icons via `` from a central SVG sprite file into your content. The plugin is deliberately _not_ an icon collection with an import UI — every icon must exist as a `` element in a sprite file that you build, maintain, and version yourself. This article shows you how to create your own icon set: create a folder full of SVG files, build them with [svgforge-cli](https://github.com/svgforge/svgforge-cli/) into a sprite file in one line, and hook it into the plugin. Including the **directory-marker trick**, which turns your subfolders into filter groups in the icon picker automatically. @@ -71,10 +73,10 @@ svgforge --symbol --dest=out 'assets/./**/*.svg' The trick is the `./` right in the middle of the glob: it is the **directory marker**. Everything before it is only the base from which the icon ID is calculated. Without the marker, the base folder name would bleed into every ID: -| Glob | Icon ID | Group | -|---|---|---| -| `assets/**/*.svg` | `assets--actions--add_circle` | `assets` (single, useless group) | -| `assets/./**/*.svg` | `actions--add_circle` | `actions` | +| Glob | Icon ID | Group | +| ------------------- | ----------------------------- | -------------------------------- | +| `assets/**/*.svg` | `assets--actions--add_circle` | `assets` (single, useless group) | +| `assets/./**/*.svg` | `actions--add_circle` | `actions` | With `./`, you get compact IDs like `actions--add_circle` from `assets/actions/add_circle.svg`. The base name `assets` disappears, and each subfolder level becomes a `--` segment — the picker turns it into the group filter. Without the marker, all icons would share the identical `assets--` prefix and the filter would be useless. @@ -88,21 +90,19 @@ After the run, the finished sprite lives at `out/symbol/sprite.svg`. If you pref ```json { - "dest": "./dist/material", - "shape": { - "transform": [ - { - "svgo": { - "plugins": [ - { "name": "removeAttrs", "params": { "attrs": "fill" } } - ] - } - } - ] - }, - "mode": { - "symbol": { "sprite": "sprite.svg", "render": { "css": false } } - } + "dest": "./dist/material", + "shape": { + "transform": [ + { + "svgo": { + "plugins": [{ "name": "removeAttrs", "params": { "attrs": "fill" } }] + } + } + ] + }, + "mode": { + "symbol": { "sprite": "sprite.svg", "render": { "css": false } } + } } ``` @@ -146,4 +146,4 @@ The plugin distinguishes automatically: multicolored sets (like Tango) keep thei A custom icon set is therefore: a folder with SVG files, a build command with the `./` directory marker, and an upload (or a filter) in the plugin. The subfolders automatically become filter groups in the picker. The structure and configs from [svgforge/default-icons](https://github.com/svgforge/default-icons) serve as a starting point. -**Tip:** If you work with a CI/CD pipeline, you can add your icons as individual SVGs to your theme. A GitHub workflow generates the `sprite.svg` during the build — the installable ZIP then contains the theme including the generated `sprite.svg`. \ No newline at end of file +**Tip:** If you work with a CI/CD pipeline, you can add your icons as individual SVGs to your theme. A GitHub workflow generates the `sprite.svg` during the build — the installable ZIP then contains the theme including the generated `sprite.svg`. diff --git a/src/content/blog/defs-vs-symbol-sprites.md b/src/content/blog/defs-vs-symbol-sprites.md index 13d2b7a..7c75a92 100644 --- a/src/content/blog/defs-vs-symbol-sprites.md +++ b/src/content/blog/defs-vs-symbol-sprites.md @@ -1,15 +1,17 @@ --- + title: defs vs symbol sprites description: When should you choose and when ? Both are inline sprite techniques — this post explains the differences based on the SVG spec. pubDate: 2026-03-10 tags: - - tutorial - - svg +- tutorial +- svg + --- When should you choose `` and when ``? -This post compares both inline sprite approaches — and yes, the two are *not* +This post compares both inline sprite approaches — and yes, the two are _not_ interchangeable. `` and `` are siblings from the same family of [structural elements](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element#structural_elements), but they serve different purposes, defined by the specification itself. @@ -20,16 +22,16 @@ Both elements have been part of SVG since the very beginning and are covered in both the [SVG 1.1 spec](https://www.w3.org/TR/SVG11/struct.html) and the [SVG 2 draft](https://www.w3.org/TR/SVG2/struct.html): -| Element | SVG 1.1 | SVG 2 | MDN reference | -| --- | --- | --- | --- | -| `` | [The defs element](https://www.w3.org/TR/SVG11/struct.html#DefsElement) | [The defs element](https://www.w3.org/TR/SVG2/struct.html#DefsElement) | [MDN ``](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/defs) | +| Element | SVG 1.1 | SVG 2 | MDN reference | +| ---------- | --------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | +| `` | [The defs element](https://www.w3.org/TR/SVG11/struct.html#DefsElement) | [The defs element](https://www.w3.org/TR/SVG2/struct.html#DefsElement) | [MDN ``](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/defs) | | `` | [The symbol element](https://www.w3.org/TR/SVG11/struct.html#SymbolElement) | [The symbol element](https://www.w3.org/TR/SVG2/struct.html#SymbolElement) | [MDN ``](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/symbol) | -| `` | [The use element](https://www.w3.org/TR/SVG11/struct.html#UseElement) | [The use element](https://www.w3.org/TR/SVG2/struct.html#UseElement) | [MDN ``](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/use) | +| `` | [The use element](https://www.w3.org/TR/SVG11/struct.html#UseElement) | [The use element](https://www.w3.org/TR/SVG2/struct.html#UseElement) | [MDN ``](https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/use) | ## What `` is The specification describes `` as a **reference container**: a place to -store objects that are *not rendered directly* but **referenced from +store objects that are _not rendered directly_ but **referenced from elsewhere**. Elements inside `` have an implicit `display:none` — they exist in the document tree, but nothing is drawn until something points at them via an IRI reference (`url(#id)`, ``, …). @@ -46,7 +48,7 @@ them via an IRI reference (`url(#id)`, ``, …). ``` -That is the *primary* use case of ``: it hosts **helper objects** +That is the _primary_ use case of ``: it hosts **helper objects** (gradients, patterns, filters, masks, markers, clip paths) that other elements pull in. It is not designed as an "icon library" element — it simply happens to work for that, because any element, including an `` @@ -55,7 +57,7 @@ with an ID, can be placed inside and later cloned via ``. ## What `` is `` is fundamentally different: it is a **graphical template object** -that is *instantiated* by ``. +that is _instantiated_ by ``. > The `symbol` element is used to define graphical template objects which > can be instantiated by a `use` element. @@ -81,7 +83,7 @@ This matters because of how `` renders its target: > — [SVG 1.1, 5.6](https://www.w3.org/TR/SVG11/struct.html#UseElement) When a `` instantiates a ``, the symbol becomes an inner -`` — and that inner `` *inherits the symbol's `viewBox`*. The +`` — and that inner `` _inherits the symbol's `viewBox`_. The icon thus gets proper, aspect-ratio-aware scaling for free. You do **not** need to repeat the `viewBox` on the `` wrapper: @@ -109,7 +111,7 @@ A `` can reference either (``) or [an external SVG file](https://caniuse.com/mdn-svg_elements_use_external_uri) (``). Both work for `` and `` alike — -*because* both are just ID-targets. +_because_ both are just ID-targets. There is a catch, though: an external `` reference creates a **separate DOM** (see [CSS-Tricks, "SVG use with external reference"](https://css-tricks.com/svg-use-with-external-reference-take-2)). @@ -117,7 +119,7 @@ That means: - you can style the `href` target from outside CSS, but **not** individual shapes inside the sprite (`#icon .path-1` won't match), -- references *inside* the sprite file (e.g. a gradient `fill="url(#grad)"`) +- references _inside_ the sprite file (e.g. a gradient `fill="url(#grad)"`) may not resolve in Chrome when the sprite is loaded externally. Whether you inline the sprite or fetch it externally, `` and @@ -158,17 +160,17 @@ Enable them in your config and get both variants: ```json { - "dest": "out", - "mode": { - "defs": { - "sprite": "svg/sprite.defs.svg", - "example": true - }, - "symbol": { - "sprite": "svg/sprite.symbol.svg", - "example": true - } - } + "dest": "out", + "mode": { + "defs": { + "sprite": "svg/sprite.defs.svg", + "example": true + }, + "symbol": { + "sprite": "svg/sprite.symbol.svg", + "example": true + } + } } ``` @@ -188,11 +190,11 @@ over ``: 2. **Scaling semantics built in.** `viewBox` + `preserveAspectRatio` even let a single icon render at different sizes and aspect ratios from one definition — impossible with a plain `` or `` in ``. -3. **Clearer semantics.** `` is *made for* reusable graphical +3. **Clearer semantics.** `` is _made for_ reusable graphical templates; `` is meant for helper objects. -**Use ``** when your icons are not self-contained units but *parts that -other icons reference* — shared gradients, filters, masks, or clip paths that +**Use ``** when your icons are not self-contained units but _parts that +other icons reference_ — shared gradients, filters, masks, or clip paths that several symbols pull in. In a hybrid setup it is perfectly normal to wrap every icon in `` and put the shared helpers in a `` above them. @@ -209,9 +211,9 @@ identifiers are the way to go — which is what svgforge's [`view`](https://css-tricks.com/svg-fragment-identifiers-work/) modes produce (``). A quick decision guide: -| Need | Mode | -| --- | --- | -| Inline icons, styleable with CSS/`currentColor`, reusable many times | `symbol` (or `defs`) | +| Need | Mode | +| --------------------------------------------------------------------- | -------------------------------- | +| Inline icons, styleable with CSS/`currentColor`, reusable many times | `symbol` (or `defs`) | | Stylesheet-driven icons with cacheable, externally referenced sprites | `symbol` + `render: {css: true}` | -| `` or `background-image` icons | `stack` | -| Foreground images with browser-native slicing | `view` | \ No newline at end of file +| `` or `background-image` icons | `stack` | +| Foreground images with browser-native slicing | `view` | diff --git a/src/content/blog/optimizing-svg-files.md b/src/content/blog/optimizing-svg-files.md index f2a0773..8ac68fa 100644 --- a/src/content/blog/optimizing-svg-files.md +++ b/src/content/blog/optimizing-svg-files.md @@ -1,11 +1,13 @@ --- + title: Optimizing SVG files description: How to customize the built-in SVGO v4 optimization in svgforge-cli with the shape.transform config. pubDate: 2026-02-18 tags: - - tips - - svg - - svgo +- tips +- svg +- svgo + --- A few practical tips for shrinking SVG files before they are baked into sprites. @@ -47,28 +49,28 @@ Create a JSON config file and point the CLI at it with `--config`: ```json { - "dest": "out", - "shape": { - "transform": [ - { - "svgo": { - "plugins": [ - "preset-default", - { "name": "removeViewBox" }, - { "name": "removeTitle" }, - { "name": "removeXMLProcInst" }, - { "name": "removeDoctype" } - ] - } - } - ] - }, - "mode": { - "view": { - "sprite": "svg/sprite.view.svg", - "example": true - } - } + "dest": "out", + "shape": { + "transform": [ + { + "svgo": { + "plugins": [ + "preset-default", + { "name": "removeViewBox" }, + { "name": "removeTitle" }, + { "name": "removeXMLProcInst" }, + { "name": "removeDoctype" } + ] + } + } + ] + }, + "mode": { + "view": { + "sprite": "svg/sprite.view.svg", + "example": true + } + } } ``` @@ -85,32 +87,32 @@ the built-in defaults entirely. ## Disabling specific plugins -More often than you want to add plugins, you want to turn one *off*. Use +More often than you want to add plugins, you want to turn one _off_. Use `preset-default` with `overrides`: ```json { - "shape": { - "transform": [ - { - "svgo": { - "plugins": [ - { - "name": "preset-default", - "params": { - "overrides": { - "cleanupIds": false, - "removeHiddenElems": false - } - } - }, - { "name": "removeViewBox" }, - { "name": "removeTitle" } - ] - } - } - ] - } + "shape": { + "transform": [ + { + "svgo": { + "plugins": [ + { + "name": "preset-default", + "params": { + "overrides": { + "cleanupIds": false, + "removeHiddenElems": false + } + } + }, + { "name": "removeViewBox" }, + { "name": "removeTitle" } + ] + } + } + ] + } } ``` @@ -127,26 +129,26 @@ individual shapes. Remove the `removeDimensions` plugin: ```json { - "shape": { - "transform": [ - { - "svgo": { - "plugins": [ - { - "name": "preset-default", - "params": { - "overrides": { - "removeDimensions": false - } - } - }, - { "name": "removeViewBox" }, - { "name": "removeTitle" } - ] - } - } - ] - } + "shape": { + "transform": [ + { + "svgo": { + "plugins": [ + { + "name": "preset-default", + "params": { + "overrides": { + "removeDimensions": false + } + } + }, + { "name": "removeViewBox" }, + { "name": "removeTitle" } + ] + } + } + ] + } } ``` @@ -157,13 +159,13 @@ accessibility, turn off the relevant plugins: ```json { - "name": "preset-default", - "params": { - "overrides": { - "removeTitle": false, - "removeDesc": false - } - } + "name": "preset-default", + "params": { + "overrides": { + "removeTitle": false, + "removeDesc": false + } + } } ``` @@ -177,22 +179,22 @@ When output size is everything, add extra plugins beyond the default: ```json { - "shape": { - "transform": [ - { - "svgo": { - "plugins": [ - "preset-default", - { "name": "removeViewBox" }, - { "name": "removeTitle" }, - { "name": "removeDimensions" }, - { "name": "removeStyleElement" }, - { "name": "removeScriptElement" } - ] - } - } - ] - } + "shape": { + "transform": [ + { + "svgo": { + "plugins": [ + "preset-default", + { "name": "removeViewBox" }, + { "name": "removeTitle" }, + { "name": "removeDimensions" }, + { "name": "removeStyleElement" }, + { "name": "removeScriptElement" } + ] + } + } + ] + } } ``` @@ -203,20 +205,20 @@ attributes rather than `