/
Post.php
34 lines (31 loc) · 891 Bytes
/
Post.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
<?php
class Post {
public $title;
public $layout = 'post';
public $tags = [];
public $categories = [];
public $content;
public $permalink;
public $date;
private function generateFilename() {
$parsed = parse_url($this->permalink);
$path = substr($parsed['path'], 9);
return str_replace('.html' , '.md', $this->date . '-' . $path);
}
public function getConvertedFileContent() {
$filename = $this->generateFilename();
$tags = implode(',' , $this->tags);
$cats = implode(',' , $this->categories);
$lines = [
'---',
'layout: post',
"title: $this->title",
"tags: [$tags]",
"categories: [$cats]",
'',
'---',
$this->content
];
file_put_contents($filename, implode("\n", $lines));
}
}