-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
142 lines (127 loc) · 4.34 KB
/
Copy pathconfig.php
File metadata and controls
142 lines (127 loc) · 4.34 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
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
136
137
138
139
140
141
142
<?php
use Carbon\Carbon;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;
use NickMoline\Models\Post;
return [
'baseUrl' => 'http://localhost:8000',
'production' => false,
'siteName' => 'NickMoline.com',
'siteDescription' => 'The Personal website of Nick Moline',
'siteAuthor' => 'Nick Moline',
'social' => [
'mastodon' => 'https://subspacelink.com/@nickmoline',
'facebook' => 'NickMoline',
'twitter' => 'NickMoline',
'github' => 'NickMoline',
'linkedin' => 'NickMoline',
'instagram' => 'NickMoline',
'email' => 'nickmoline@gmail.com',
'dev' => 'nickmoline',
'youtube' => 'nickmoline'
],
// collections
'collections' => [
'posts' => [
'map' => function ($post) {
return Post::fromItem($post);
},
'author' => 'Nick Moline', // Default author, if not provided in a post
'sort' => '-filename',
'path' => function ($page) {
return $page->getPermalink();
},
'extends' => '_layouts.post',
'section' => 'content',
],
'categories' => [
'path' => '/blog/categories/{filename}/',
'posts' => function ($page, $allPosts) {
return $allPosts->filter(function ($post) use ($page) {
return $post->inCategory($page->getFilename());
});
},
],
'tags' => [
'path' => '/blog/tags/{filename}/',
'posts' => function ($page, $allPosts) {
return $allPosts->filter(function ($post) use ($page) {
return $post->tags ? in_array($page->getFilename(), $post->tags, true) : false;
});
},
'items' => function ($config) {
// Figure out how to get tags from posts... first figure out how to get posts
},
],
],
'postUrl' => function ($page, $filename) {
if (!$page->collection) {
return $filename;
}
if ($page->collection[$filename]) {
return $page->collection[$filename]->getUrl();
}
return $filename;
},
'publishDate' => function ($page) {
if (Arr::has($page->items, 'published')) {
return Carbon::parse($page->published);
} elseif (Arr::has($page->items, 'date')) {
return Carbon::parse($page->date);
} elseif (preg_match("(\d{4}-\d{2}-\d{2})", $page->getFilename(), $matches)) {
return Carbon::parse($matches[0]);
}
return Carbon::now();
},
'getPermalink' => function ($page) {
if ($page->permalink) {
return preg_replace("@/$@", "", $page->permalink);
}
$date = $page->publishDate();
$slug = preg_replace("@^(\d{4}-\d{2}-\d{2}-)@", "", $page->getFilename());
return $date->format("/Y/m/d/") . $slug;
},
'postLink' => function ($page, $filename, $text = null) {
$link = $page->postUrl($filename);
if (!$text) {
$text = $filename;
}
if ($link !== $filename) {
return "<a href=\"{$link}\">{$text}</a>";
} else {
return $filename;
}
},
// helpers
'canonicalUrl' => function ($page) {
if ($page->canonical) {
return $page->canonical;
}
return $page->getUrl();
},
'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;
},
'isActive' => function ($page, $path) {
return Str::endsWith(trimPath($page->getPath()), trimPath($path));
},
];