-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
49 lines (40 loc) · 970 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php declare(strict_types=1);
use Kirby\Content\Field;
use Kirby\Filesystem\F;
use Kirby\Toolkit\A;
/**
* Joins path fragments to a single path with DIRECTORY_SEPARATOR
*
* @param string[] $fragments
* @return string
*/
function path(...$fragments): string
{
return A::join($fragments, DIRECTORY_SEPARATOR);
}
/**
* Reads an SVG file and returns it as string.
*
* @param string $file
*
* @return string
*/
function inline_svg(string $file, string $class = null): string
{
$svg = F::read($file);
if ($class) {
$svg = str_replace('<svg', sprintf('<svg class="%s"', $class), $svg);
}
return $svg ?: '';
}
function inline_icon(Field|string $icon, string $class = null): string
{
if ($icon instanceof Field) {
$icon = $icon->value();
}
$source = option('tobimori.icon-field.folder');
if (is_callable($source)) {
$source = $source();
}
return inline_svg(path($source, $icon), $class);
}