Skip to content

Commit 1a41965

Browse files
committed
🐛 fix date handler
Signed-off-by: bnomei <[email protected]>
1 parent 149a3b8 commit 1a41965

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ return [
113113
| link | `function($page){...}` | callback to return the link |
114114
| text | `function($page){...}` | callback to return the text |
115115
| info | `function($page){...}` | callback to return the info |
116-
| format | `Y/m/d H:i:s` | date format string |
116+
| format | `fn($datetime){...}` | custom date format callback |
117117
| hooks | `true` | use hooks to track users modified pages |
118118
| limit | `7` | limit list and cache items |
119119
| expire | `1` | cache will expire n-minutes |

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Kirby Section to display recently modified content pages",
44
"license": "MIT",
55
"type": "kirby-plugin",
6-
"version": "4.2.0",
6+
"version": "4.2.1",
77
"authors": [
88
{
99
"name": "Bruno Meilick",

index.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66
App::plugin('bnomei/recently-modified', [
77
'options' => [
88
'query' => "site.index(true).sortBy('modified', 'desc').onlyModifiedByUser",
9-
'format' => null,
9+
'format' => function($datetime): string {
10+
$handler = kirby()->option('date.handler') ?? 'date';
11+
$formats = [
12+
'date' => 'Y/m/d H:i:s',
13+
'intl' => 'yyyy/MM/dd HH:mm:ss', // https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax
14+
'strftime' => '%Y/%m/%d %H:%M:%S'
15+
];
16+
$format = $formats[$handler] ?? $formats['date'];
17+
18+
return Str::date($datetime, $format, $handler);
19+
},
1020
'info' => function (\Kirby\Cms\Page $page) {
11-
return $page->modified(option('bnomei.recently-modified.format'));
21+
return option('bnomei.recently-modified.format')($page->modified());
1222
},
1323
'link' => function (\Kirby\Cms\Page $page) {
1424
return $page->panel()->url();
@@ -29,7 +39,7 @@
2939
return $user ? (string)$user->nameOrEmail() : '';
3040
},
3141
'datetime' => function () {
32-
return $this->model()->modified(option('bnomei.recently-modified.format'));
42+
return option('bnomei.recently-modified.format')($this->model()->modified());
3343
},
3444
],
3545
],
@@ -192,28 +202,20 @@
192202
$id = explode('?', ltrim(str_replace(['/pages/', '/_drafts/', '+', ' '], ['/', '/', '/', '/'], $id), '/'))[0];
193203
$kirby = App::instance(null, true);
194204

195-
$handler = $kirby->option('date.handler') ?? 'date';
196-
$formats = [
197-
'date' => 'Y/m/d H:i:s',
198-
'intl' => 'yyyy/MM/dd HH:mm:ss', // https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax
199-
'strftime' => '%Y/%m/%d %H:%M:%S'
200-
];
201-
$format = $kirby->option('bnomei.recently-modified.format') ?? $formats[$handler] ?? $formats['date'];
202-
203205
if ($id === 'site') {
204206
$user = site()->findRecentlyModifiedByUser();
205207
$username = $user ? (string)$user->nameOrEmail() : '';
206208
return [
207209
'auser' => $username,
208-
'datetime' => Str::date(site()->modifiedTimestamp(), $format, $handler),
210+
'datetime' => option('bnomei.recently-modified.format')(site()->modifiedTimestamp()),
209211
];
210212
}
211213
if ($page = $kirby->page($id)) {
212214
$user = $page->findRecentlyModifiedByUser();
213215
$username = $user ? (string)$user->nameOrEmail() : '';
214216
return [
215217
'auser' => $username,
216-
'datetime' => $page->modified($format, $handler),
218+
'datetime' => option('bnomei.recently-modified.format')($page->modified()),
217219
];
218220
}
219221
return \Kirby\Http\Response::json([], 404);

vendor/composer/installed.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php return array(
22
'root' => array(
33
'name' => 'bnomei/kirby3-recently-modified',
4-
'pretty_version' => '4.2.0',
5-
'version' => '4.2.0.0',
4+
'pretty_version' => '4.2.1',
5+
'version' => '4.2.1.0',
66
'reference' => null,
77
'type' => 'kirby-plugin',
88
'install_path' => __DIR__ . '/../../',
@@ -11,8 +11,8 @@
1111
),
1212
'versions' => array(
1313
'bnomei/kirby3-recently-modified' => array(
14-
'pretty_version' => '4.2.0',
15-
'version' => '4.2.0.0',
14+
'pretty_version' => '4.2.1',
15+
'version' => '4.2.1.0',
1616
'reference' => null,
1717
'type' => 'kirby-plugin',
1818
'install_path' => __DIR__ . '/../../',

0 commit comments

Comments
 (0)