This repository has been archived by the owner on Jul 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
96 lines (93 loc) · 4.06 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
<?php
@include_once __DIR__ . '/vendor/autoload.php';
@include_once __DIR__ . '/src/CloudFrontInvalidations.php';
use Liftric\CloudFrontInvalidations;
Kirby::plugin('liftric/cloudfrontinvalidations', [
'options' => [
'distributionID' => null,
'awsAccessKeyID' => null,
'awsSecretAccessKey' => null,
'dependantUrlsForPage' => function ($hook, $page, $oldPage = null) {
return $oldPage ? [$page->url(), $oldPage->url()] : $page->url();
},
'dependantUrlsForFile' => function ($hook, $file, $oldFile = null) {
$clearParentOnly = in_array($hook, [
'file.changeSort:after',
'file.create:after',
'file.update:after',
]);
$urls = $clearParentOnly ? [$file->parent()->url()] : [$file->url(), $file->parent()->url()];
if ($oldFile && !$clearParentOnly) {
$urls[] = $oldFile->url();
// Shouldn't need to add $oldFile->parent()->url() because the parent should be the same as the "new" file's parent.
}
return $urls;
},
'dependantUrlsForSite' => function ($hook, $site, $oldSite = null) {
return $site->url();
},
],
'api' => [
'routes' => [
[
'pattern' => 'cloudfront/invalidate',
'method' => 'get',
'action' => function () {
return CloudFrontInvalidations::invalidate();
}
]
]
],
'hooks' => [
// // Page
// 'page.changeNum:after' => function ($newPage) {
// CloudFrontInvalidations::handlePageHook('page.changeNum:after', $newPage);
// },
// 'page.changeSlug:after' => function ($newPage, $oldPage) {
// CloudFrontInvalidations::handlePageHook('page.changeSlug:after', $newPage, $oldPage);
// },
// 'page.changeStatus:after' => function ($newPage) {
// CloudFrontInvalidations::handlePageHook('page.changeStatus:after', $newPage);
// },
// 'page.changeTemplate:after' => function ($newPage) {
// CloudFrontInvalidations::handlePageHook('page.changeTemplate:after', $newPage);
// },
// 'page.changeTitle:after' => function ($newPage) {
// CloudFrontInvalidations::handlePageHook('page.changeTitle:after', $newPage);
// },
// 'page.create:after' => function ($page) {
// CloudFrontInvalidations::handlePageHook('page.create:after', $page);
// },
// 'page.delete:after' => function ($status, $page) {
// CloudFrontInvalidations::handlePageHook('page.delete:after', $page);
// },
// 'page.update:after' => function ($newPage, $oldPage) {
// CloudFrontInvalidations::handlePageHook('page.changeSlug:after', $newPage, $oldPage);
// },
//
// // File
// 'file.changeName:after' => function ($newFile, $oldFile) {
// CloudFrontInvalidations::handleFileHook('file.changeName:after', $newFile, $oldFile);
// },
// 'file.changeSort:after' => function ($newFile, $oldFile) {
// CloudFrontInvalidations::handleFileHook('file.changeSort:after', $newFile, $oldFile);
// },
// 'file.create:after' => function ($file) {
// CloudFrontInvalidations::handleFileHook('file.create:after', $file);
// },
// 'file.delete:after' => function ($status, $file) {
// CloudFrontInvalidations::handleFileHook('file.delete:after', $file);
// },
// 'file.replace:after' => function ($newFile, $oldFile) {
// CloudFrontInvalidations::handleFileHook('file.replace:after', $newFile, $oldFile);
// },
// 'file.update:after' => function ($newFile, $oldFile) {
// CloudFrontInvalidations::handleFileHook('file.update:after', $newFile, $oldFile);
// },
//
// // Site
// 'site.update:after' => function ($newSite, $oldSite) {
// CloudFrontInvalidations::handleSiteHook('site.update:after', $newSite);
// },
],
]);