This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PagesTableSeeder.php
62 lines (51 loc) · 2.29 KB
/
PagesTableSeeder.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
<?php
# database/seeds/PagesTableSeeder.php
use App\Models\Page;
use Illuminate\Database\Seeder;
use Kurenai\DocumentParser;
class PagesTableSeeder extends Seeder
{
public function run()
{
// update tables instead of overwriting (think timestamps, original...)
$parser = new DocumentParser;
$it = new RecursiveDirectoryIterator(realpath(dirname(dirname(dirname(__FILE__)))."/storage/app/pages"));
$display = Array ( 'md' );
foreach(new RecursiveIteratorIterator($it) as $file)
{
$exp = explode('.', $file);
if (basename($file)!=='.' && basename($file)!=='..' && in_array(strtolower(array_pop($exp)), $display)) {
$original_date = basename(dirname(dirname(dirname($file)))) . '-' . basename(dirname(dirname($file))) . '-' . basename(dirname($file));
if ($file == realpath("./storage/app/pages") . 'index.md') {
$type = 'index';
}
$source = file_get_contents($file);
$document = $parser->parse($source);
if ($document->get('slug')) {
$slug = substr(str_replace('+', '-', urlencode(strtolower(preg_replace("#[[:punct:]]#", "-", $document->get('slug'))))), 0, 50);
} else {
$slug = substr(str_replace('+', '-', urlencode(strtolower(preg_replace("#[[:punct:]]#", "-", $document->get('title'))))), 0, 50);
}
if ($document->get('type')) {
$type = $document->get('type');
} else {
$type = 'default';
}
if ($document->get('style')) {
$style = $document->get('style');
} else {
$style = 'default';
}
$page = Page::create([
'page_title' => ucfirst($document->get('title')),
'slug' => $slug,
'body' => $document->getHtmlContent(),
'published' => $document->get('published') == 'false' || false,
'type' => $type,
'style' => $style,
'transparent' => $document->get('transparent') == 'false' || false,
]);
}
}
}
}