-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
102 lines (96 loc) · 2.94 KB
/
index.php
File metadata and controls
102 lines (96 loc) · 2.94 KB
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
<?php
use arnoson\KirbyLoupe;
use Kirby\Cms\App;
use Kirby\Cms\Page;
App::plugin("arnoson/kirby-loupe", [
"options" => [
"pages" => fn() => true,
"fields" => [],
"commands" => [
"reindex" => function () {
$count = KirbyLoupe::reindex();
return [
"status" => 200,
"message" =>
$count === 1 ? "Reindexed 1 page" : "Reindexed $count pages",
];
},
],
],
"fields" => [
"loupe-reindex" => [],
],
"hooks" => [
"page.changeStatus:after" => function (Page $newPage, Page $oldPage) {
if ($newPage->status() === "draft") {
KirbyLoupe::loupe()->deleteDocument($newPage->uuid()->toString());
} elseif (
KirbyLoupe::includePage($newPage) &&
$oldPage->status() === "draft"
) {
KirbyLoupe::indexPage($newPage);
}
},
"page.update:after" => function (Page $newPage) {
if (KirbyLoupe::includePage($newPage) && $newPage->status() !== "draft") {
KirbyLoupe::indexPage($newPage);
} else {
KirbyLoupe::loupe()->deleteDocument($newPage->uuid()->toString());
}
},
"page.delete:before" => function (Page $page) {
KirbyLoupe::loupe()->deleteDocument($page->uuid()->toString());
},
],
"api" => [
"routes" => [
[
"pattern" => "plugin-kirby-loupe/reindex-all",
"action" => fn() => ["count" => KirbyLoupe::reindex()],
],
[
"pattern" => "plugin-kirby-loupe/reindex-chunk/start",
"action" => function () {
KirbyLoupe::clearIndex();
$uuids = [];
$pages = site()
->index()
->filterBy(fn($page) => KirbyLoupe::includePage($page));
foreach ($pages as $page) {
$uuids[] = $page->uuid()->toString();
}
return $uuids;
},
],
[
"pattern" => "plugin-kirby-loupe/reindex-chunk",
"method" => "POST",
"action" => function () {
$uuids = kirby()->request()->data()["uuids"];
foreach ($uuids as $uuid) {
KirbyLoupe::indexPage(page($uuid));
}
return true;
},
],
],
],
"translations" => [
"en" => [
"arnoson.kirby-loupe.reindex-site" => "Reindex Site",
"arnoson.kirby-loupe.success" => "Successfully reindexed {count} pages",
"arnoson.kirby-loupe.error" => "Indexing couldn't no be completed",
"arnoson.kirby-loupe.info-chunk-reindex" =>
"Please keep the browser tab open until the indexing is complete",
],
"de" => [
"arnoson.kirby-loupe.reindex-site" => "Seite neu indizieren",
"arnoson.kirby-loupe.success" =>
"{count} Seiten erfolgreich neu indiziert",
"arnoson.kirby-loupe.error" =>
"Indizierung konnte nicht abgeschlossen werden",
"arnoson.kirby-loupe.info-chunk-reindex" =>
"Bis zum Abschluss der Indizierung bitte den Browser-Tab geöffnet lassen",
],
],
]);