-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
135 lines (109 loc) · 5.15 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
@include_once __DIR__ . '/vendor/autoload.php';
use Kirby\Cms\App;
use Kirby\Cms\Page;
App::plugin('avoskitchen/kitchen', [
'options' => [
'fractions' => true,
'decimals' => 2,
'decimalPoint' => '.',
'thousandsSeparator' => ',',
'ingredientClass' => 'ingredient',
'ingredientGroupClass' => 'ingredient-group',
'ingredientAmountClass' => 'ingredient-amount',
'ingredientItemClass' => 'ingredient-item',
],
'blueprints' => [
# fields
'kitchen/fields/category-options' => __DIR__ . '/blueprints/fields/category-options.yml',
'kitchen/fields/category' => __DIR__ . '/blueprints/fields/category.yml',
'kitchen/fields/cover' => __DIR__ . '/blueprints/fields/cover.yml',
'kitchen/fields/cuisine-options' => __DIR__ . '/blueprints/fields/cuisine-options.yml',
'kitchen/fields/cuisines' => __DIR__ . '/blueprints/fields/cuisines.yml',
'kitchen/fields/lastedited' => __DIR__ . '/blueprints/fields/lastedited.yml',
'kitchen/fields/tags' => __DIR__ . '/blueprints/fields/tags.yml',
'kitchen/fields/unit-options' => __DIR__ . '/blueprints/fields/unit-options.yml',
# pages
'pages/knowledge' => __DIR__ . '/blueprints/pages/knowledge.yml',
'pages/recipe' => __DIR__ . '/blueprints/pages/recipe.yml',
'pages/recipes' => __DIR__ . '/blueprints/pages/recipes.yml',
'pages/term' => __DIR__ . '/blueprints/pages/term.yml',
# pages are also registred with a namespaced alias, so they can be extended
# in your own page blueprints
'kitchen/pages/knowledge' => __DIR__ . '/blueprints/pages/knowledge.yml',
'kitchen/pages/recipe' => __DIR__ . '/blueprints/pages/recipe.yml',
'kitchen/pages/recipes' => __DIR__ . '/blueprints/pages/recipes.yml',
'kitchen/pages/term' => __DIR__ . '/blueprints/pages/term.yml',
# sections
'kitchen/sections/files' => __DIR__ . '/blueprints/sections/files.yml',
'kitchen/sections/recipe-content' => __DIR__ . '/blueprints/sections/recipe-content.yml',
'kitchen/sections/recipe-meta' => __DIR__ . '/blueprints/sections/recipe-meta.yml',
],
'hooks' => [
'page.create:before' => function (Page $page, array $input) {
switch ($input['template']) {
case 'knowledge':
$knowledgePages = site()->children()->filterBy('template', 'knowledge');
if ($knowledgePages->count() > 0) {
throw new Exception('Your site can only contain one knowledge base page. Please delete the page "' . $knowledgePages->first()->title() . '" before creating a new knowledge base page.');
}
if ($page->parent() !== null) {
throw new Exception('A knowledge base page can only be created at the top-level of your site.');
}
break;
}
},
'page.create:after' => function (Page $page) {
switch ($page->template()) {
case 'term':
case 'recipe':
// inspired by the kirby last edited field by dennis kerzig (released under the mit license)
// https://github.com/wottpal/kirby-last-edited
$now = date('Y-m-d H:i:s');
$page->update([
'created' => $now,
'lastEdited' => $now,
], null);
break;
}
},
'page.update:after' => function (Page $newPage, Page $oldPage) {
switch ($newPage->template()) {
case 'term':
case 'recipe':
$newPage->update([
'lastEdited' => date('Y-m-d H:i:s'),
], null);
break;
}
},
'system.loadPlugins:after' => function () {
$kirby = kirby();
if ($kirby->option('date.handler') !== 'intl') {
throw new Exception('The kitchen plugin requires `date.handler` to be `intl`, see https://getkirby.com/docs/reference/system/options/date');
}
if (! $kirby->multilang() && empty($kirby->option('locale'))) {
throw new Exception('Please use languages or set `locale` in your config file.');
}
}
],
'pageModels' => [
'knowledge' => AvosKitchen\Kitchen\Models\KnowledgePage::class,
'recipe' => AvosKitchen\Kitchen\Models\RecipePage::class,
'recipes' => AvosKitchen\Kitchen\Models\RecipesPage::class,
'term' => AvosKitchen\Kitchen\Models\TermPage::class,
],
'snippets' => [
'yield' => __DIR__ . '/snippets/yield.php',
],
'tags' => [
'recipe' => require __DIR__ . '/tags/recipe.php',
'term' => require __DIR__ . '/tags/term.php',
],
'templates' => [
'recipe' => __DIR__ . '/templates/recipe.php',
'recipes' => __DIR__ . '/templates/recipes.php',
'knowledge' => __DIR__ . '/templates/knowledge.php',
'term' => __DIR__ . '/templates/term.php',
],
]);