-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
108 lines (96 loc) · 3.16 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
@include_once __DIR__.'/vendor/autoload.php';
Kirby::plugin('bnomei/storybook', [
'options' => [
'cli' => fn () => php_sapi_name() === 'cli',
'folder' => function (): ?string {
foreach ([
kirby()->root('index').'/stories',
kirby()->root('index').'/../stories',
] as $dir) {
if (Dir::exists($dir)) {
return $dir;
}
}
$finder = new \Symfony\Component\Finder\Finder;
$finder->files()->in(kirby()->root('index'))
->notPath('/.*node_modules.*/')
->name('stories');
foreach ($finder->directories() as $dir) {
return $dir->getRealPath();
}
return null;
},
'stories' => [
'json' => fn () => class_exists('Kirby\Kql\Kql'),
'yml' => true,
'ignore' => [
'vendor',
'site/plugins/kirby3-feed',
'site/plugins/kirby3-htmlhead',
],
],
],
'commands' => [ // https://github.com/getkirby/cli
'storybook:watch' => require __DIR__.'/commands/watch.php',
],
'components' => [
'snippet' => function (\Kirby\Cms\App $kirby, $name, array $data = [], bool $slots = false) {
// support other plugins if installed
// https://github.com/lukaskleinschmidt/kirby-snippet-controller
if (function_exists('snippet_controller')) {
$data = snippet_controller($name, $data);
}
// merge data with...
$storybook = \Bnomei\Storybook::singleton();
if ($storybook->option('cli')) {
$data = $storybook->loadData(
$data,
$name
);
}
return $kirby->core()->components()['snippet'](
$kirby,
$name,
$data,
$slots,
);
},
],
]);
if (! class_exists('Bnomei\Storybook')) {
require_once __DIR__.'/classes/Storybook.php';
}
if (! function_exists('storybook')) {
function storybook(array $csf = [], ?string $filepath = null): array
{
$backfiles = debug_backtrace();
$filepath ??= $backfiles[0]['file'];
return \Bnomei\Storybook::singleton()->csf($csf, $filepath);
}
}
if (! function_exists('storybook_block')) {
function storybook_block(string $type, array $content = []): \Kirby\Cms\Block
{
return new \Kirby\Cms\Block([
'type' => $type,
'content' => $content,
]);
}
}
// Passing the $slot or $slots variables to snippets is not supported.
/*
if (! function_exists('storybook_slots')) {
function storybook_slots(array $content = [], ?string $file = null): \Kirby\Template\Slots
{
if (! $file) {
$file = \Kirby\Toolkit\Str::random(5).'.php';
}
$slots = [];
foreach ($content as $key => $value) {
$slots[$key] = new \Kirby\Template\Slot($file, $key, $value);
}
return new \Kirby\Template\Slots($slots);
}
}
*/