|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Lichtenwallner (https://lichtenwallner.at) |
|
4
|
|
|
* |
|
5
|
|
|
* @see https://github.com/jolicht/markdown-cms for the canonical source repository |
|
6
|
|
|
* @license https://github.com/jolicht/markdown-cms/blob/master/LICENSE MIT |
|
7
|
|
|
* @copyright Copyright (c) Johannes Lichtenwallner |
|
8
|
|
|
*/ |
|
9
|
|
|
declare(strict_types = 1); |
|
10
|
|
|
namespace Jolicht\MarkdownCms\ContentType; |
|
11
|
|
|
|
|
12
|
|
|
use Jolicht\MarkdownCms\Markdown\MarkdownDocument; |
|
13
|
|
|
use Jolicht\MarkdownCms\Taxonomy\Tag; |
|
14
|
|
|
|
|
15
|
|
|
class BlogEntryCreator extends AbstractContentTypeCreator |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* More separator |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
const MORE_SEPARATOR = '<!--more-->'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create blog entry |
|
26
|
|
|
* @return BlogEntry |
|
27
|
|
|
* @param MarkdownDocument $markdownDocument |
|
28
|
|
|
* @return BlogEntry |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __invoke(MarkdownDocument $markdownDocument) : BlogEntry |
|
31
|
|
|
{ |
|
32
|
|
|
$content = $markdownDocument->getContent(); |
|
33
|
|
|
if (false !== strpos($content, self::MORE_SEPARATOR)) { |
|
34
|
|
|
$parts = explode(self::MORE_SEPARATOR, $content, 2); |
|
35
|
|
|
$excerpt = trim($parts[0]); |
|
36
|
|
|
$extend = trim($parts[1]); |
|
37
|
|
|
} else { |
|
38
|
|
|
$excerpt = ''; |
|
39
|
|
|
$extend = trim($content); |
|
40
|
|
|
} |
|
41
|
|
|
$blogEntry = new BlogEntry( |
|
42
|
|
|
$markdownDocument->getParam('id'), |
|
43
|
|
|
$markdownDocument->getParam('title'), |
|
44
|
|
|
$markdownDocument->getContent(), |
|
45
|
|
|
new \DateTime($markdownDocument->getParam('created')), |
|
46
|
|
|
new \DateTime($markdownDocument->getParam('updated', $markdownDocument->getParam('created'))), |
|
47
|
|
|
$markdownDocument->getParam('draft', false), |
|
48
|
|
|
$markdownDocument->getParam('template', $this->getDefaultTemplate()), |
|
49
|
|
|
$excerpt, |
|
50
|
|
|
$extend |
|
51
|
|
|
); |
|
52
|
|
|
foreach ($markdownDocument->getParam('tags', []) as $tagKey) { |
|
53
|
|
|
$blogEntry->addTag(new Tag($tagKey)); |
|
54
|
|
|
} |
|
55
|
|
|
return $blogEntry; |
|
56
|
|
|
} |
|
57
|
|
|
} |