forked from phpearth/PHP.earth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.php
48 lines (39 loc) · 1.21 KB
/
build.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
<?php
<<<CONFIG
packages:
- "mnapoli/front-yaml: *"
CONFIG;
/**
* Build search index data for wwphp-fb.github.io.
* Usage: melody run build.php
*/
use Mni\FrontYAML\Parser;
$parser = new Parser();
$directory = __DIR__.'/_resources';
$exclude = ['.git', 'images', '.gitignore', 'CONTRIBUTING.md', 'LICENSE', 'README.md'];
$filter = function ($file, $key, $iterator) use ($exclude) {
if ($iterator->hasChildren() && !in_array($file->getFilename(), $exclude)) {
return true;
}
return ($file->isFile() && !in_array($file->getFilename(), $exclude));
};
$innerIterator = new RecursiveDirectoryIterator(
$directory,
RecursiveDirectoryIterator::SKIP_DOTS
);
$iterator = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator($innerIterator, $filter)
);
$index = ['entries' => []];
foreach ($iterator as $pathName => $fileInfo) {
$document = $parser->parse(file_get_contents($pathName));
$yaml = $document->getYAML();
$index['entries'][] = [
"title" => $yaml['title'],
"url" => $yaml['permalink'],
"date" => '',
"body" => '',
"categories" => []
];
}
file_put_contents('./assets/js/lunr/indexdata.json', json_encode($index), LOCK_EX);