Skip to content

Commit c877c7a

Browse files
committed
fix: Updates support for Kirby file UUIDs alongside path strings.
1 parent 88f2286 commit c877c7a

4 files changed

Lines changed: 18 additions & 19 deletions

File tree

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,27 @@ $ git submodule add https://github.com/scottboms/kirbytag-svg.git site/plugins/k
3333

3434
Optionally, you can specify a custom `wrapper` element to wrap the SVG along with class and role attributes that will be applied to that element. If `class` or `role` attributes are included but no `wrapper` element, a 'figure' element will be used.
3535

36+
The tag now supports all of these value types while preserving the existing path-based behavior:
37+
38+
* page-local filenames, like `icon.svg`
39+
* Kirby file IDs/paths, like `projects/example/icon.svg`
40+
* Kirby file UUIDs, like `file://abc123...`
41+
* existing root-relative or filesystem-style SVG paths, like `/assets/icons/icon.svg`
42+
3643
### Optional Tag Attributes
3744

3845
* `wrapper`: A wrapper element to surround the SVG when output in your template [optional]
3946
* `class`: A CSS class/classes to append to the wrapper element [optional]
4047
* `role`: A role attribute appended to the wrapper element [optional]
4148

42-
#### Example usage:
49+
#### Example usage:
4350

4451
```
4552
(svg: /img/deke.svg)
4653
(svg: lerxst.svg wrapper: figure class: svg role: img)
4754
(svg: /assets/icons/pratt.svg wrapper: div class: icon)
55+
(svg: projects/example/logo.svg)
56+
(svg: file://your-file-uuid)
4857
```
4958

5059
## Configuration Options

index.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use Kirby\Cms\App;
1414
use Kirby\Cms\File;
15-
use Kirby\Toolkit\F;
1615

1716
// shamelessly borrowed from distantnative/retour-for-kirby
1817
if (
@@ -23,11 +22,11 @@
2322
}
2423

2524
Kirby::plugin(
26-
name: 'scottboms/kirbytag-svg',
25+
name: 'scottboms/kirbytag-svg',
2726
info: [
2827
'homepage' => 'https://github.com/scottboms/kirbytag-svg'
2928
],
30-
version: '1.1.4',
29+
version: '1.1.5',
3130
extends: [
3231
'snippets' => [
3332
'svgtag' => __DIR__ . '/snippets/svg.php'
@@ -43,23 +42,14 @@
4342
'role'
4443
],
4544
'html' => function($tag) {
46-
$pattern = '/\//'; // identify path strings
47-
4845
$string = $tag->value;
49-
50-
if (preg_match($pattern, $string)) {
51-
$file = $tag->svg;
52-
} else {
53-
$file = $tag->parent()->file($tag->value);
54-
}
55-
56-
$svgurl = $file;
46+
$svg = $tag->file($string) ?? $string;
5747
$wrapper = $tag->wrapper ?? option('scottboms.kirbytag-svg.wrapper');
5848
$class = $tag->class;
5949
$role = $tag->role;
6050

6151
$args = array(
62-
'svg' => $svgurl,
52+
'svg' => $svg,
6353
'wrapper' => $wrapper,
6454
'class' => $class,
6555
'role' => $role,
@@ -74,4 +64,4 @@
7464
]
7565
]
7666
]
77-
);
67+
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svg",
33
"description": "Custom Kirbytag to enable using svg directly in textareas",
44
"author": "Scott Boms <plugins@scottboms.com>",
5-
"version": "1.1.4",
5+
"version": "1.1.5",
66
"type": "kirby-plugin",
77
"license": "MIT"
88
}

snippets/svg.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<?php if (isset($wrapper)): ?>
1+
<?php if (!empty($wrapper)): ?>
22
<?= '<' . $wrapper . ' class="' . $class . '"' . ' role="' . $role . '">' ?>
33
<?php endif ?>
44
<?php if($svg): ?>
55
<?= svg($svg) ?>
66
<?php endif ?>
7-
<?php if($wrapper !== ''): ?>
7+
<?php if (!empty($wrapper)): ?>
88
<?= '</' . $wrapper . '>'?>
99
<?php endif ?>

0 commit comments

Comments
 (0)