-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathgenassets.php
53 lines (38 loc) · 1.36 KB
/
genassets.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
<?php
function getDirContents($dir, &$results = array()){
$files = scandir($dir);
foreach($files as $key => $value){
$path = $dir.DIRECTORY_SEPARATOR.$value;
if(!is_dir($path) && $value !== '.DS_Store') {
$results[] = $value;
} else if($value != "." && $value != ".." && $value !== '.DS_Store') {
getDirContents($path, $results[$value]);
}
}
return $results;
}
$assets = getDirContents('public/assets');
$monthAssets = $assets;
unset( $monthAssets['intro'] );
unset( $monthAssets['end'] );
uksort( $monthAssets, "compare_months" );
function compare_months($a, $b) {
$monthA = date_parse($a);
$monthB = date_parse($b);
return $monthA["month"] - $monthB["month"];
}
// $json = 'const assets = ' . json_encode( $assets ) . '; export default assets;';
$json_pretty = json_encode( $monthAssets, JSON_PRETTY_PRINT );
// file_put_contents( 'src/assets.js', $json );
file_put_contents( 'src/assetListGenerated.json', $json_pretty );
foreach( $monthAssets as $key => $month ) {
unset( $monthAssets[ $key ] );
foreach( $month as $file => $value ) {
$monthAssets[ $key ][ $value ] = [
'caption' => $value,
'link' => ''
];
}
}
$json_pretty = json_encode( $monthAssets, JSON_PRETTY_PRINT );
file_put_contents( 'src/assetDataGenerated.json', $json_pretty );