diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2020-02-17 19:59:15 +0000 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2020-02-17 19:59:15 +0000 |
| commit | 498913806182905cc0c14bd12a61f9af26fa16b4 (patch) | |
| tree | 0c36a6df72900c184e900b274bad14aa5114fc5d /config.php | |
| parent | 12b052b1f480c5a95acd1477e28ce76f84ff7932 (diff) | |
Switch over to Jigsaw
Diffstat (limited to 'config.php')
| -rw-r--r-- | config.php | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/config.php b/config.php new file mode 100644 index 0000000..fc40865 --- /dev/null +++ b/config.php @@ -0,0 +1,63 @@ +<?php + +use Illuminate\Support\Str; + +return [ + 'baseUrl' => '', + 'production' => false, + 'siteName' => 'Blog Starter Template', + 'siteDescription' => 'Generate an elegant blog with Jigsaw', + 'siteAuthor' => 'Author Name', + + // collections + 'collections' => [ + 'posts' => [ + 'author' => 'Author Name', // Default author, if not provided in a post + 'sort' => '-date', + 'path' => 'blog/{filename}', + ], + 'categories' => [ + 'path' => '/blog/categories/{filename}', + 'posts' => function ($page, $allPosts) { + return $allPosts->filter(function ($post) use ($page) { + return $post->categories ? in_array($page->getFilename(), $post->categories, true) : false; + }); + }, + ], + ], + + // helpers + 'getDate' => function ($page) { + return Datetime::createFromFormat('U', $page->date); + }, + '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 $content[0]; + } + + $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)); + }, +]; |
