-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.php
67 lines (57 loc) · 1.92 KB
/
config.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
<?php
use Illuminate\Support\Str;
return [
'production' => false,
'domain' => 'http://dekker.test',
'siteName' => 'Claudio Dekker',
'siteAuthor' => 'Claudio Dekker',
'siteDescription' => 'Software Developer & Maintainer at InertiaJS',
'type' => 'website',
'collections' => [
'blog' => [
'type' => 'article',
'path' => 'blog/{filename}',
'author' => '@claudiodekker',
'categories' => ['articles'],
'sort' => ['-date'],
'filter' => function ($item) {
return $item->published ?? true;
},
]
],
'getDate' => fn ($page) => DateTime::createFromFormat('U', $page->date),
'getDescription' => function ($page, $maxLength = 150) {
if ($page->description) {
return $page->description;
}
if ($page->excerpt) {
return $page->excerpt;
}
if (method_exists($page, 'getContent')) {
return Str::limit(str_replace(["\n", "\r"], ' ', strip_tags($page->getContent())), $maxLength);
}
return $page->siteDescription;
},
'getExcerpt' => function ($page, $length = 255) {
if ($page->excerpt) {
return $page->excerpt;
}
$content = preg_split('/<!--more-->/m', $page->getContent(), 2);
$cleaned = trim(
strip_tags(
preg_replace(['/<pre>[\w\W]*?<\/pre>/', '/<h\d>[\w\W]*?<\/h\d>/'], '', $content[0]),
'<code>'
)
);
if (count($content) > 1) {
return $cleaned;
}
$truncated = substr($cleaned, 0, $length);
if (substr_count($truncated, '<code>') > substr_count($truncated, '</code>')) {
$truncated .= '</code>';
}
return strlen($cleaned) > $length
? preg_replace('/\s+?(\S+)?$/', '', $truncated) . ' [...]'
: $cleaned;
},
];