4
4
5
5
namespace Hyde \Framework \Services ;
6
6
7
- use Closure ;
8
7
use Hyde \Facades \Site ;
9
8
use Hyde \Foundation \RouteCollection ;
10
9
use Hyde \Framework \Actions \StaticPageBuilder ;
13
12
use Hyde \Support \Models \Route ;
14
13
use Illuminate \Console \Concerns \InteractsWithIO ;
15
14
use Illuminate \Console \OutputStyle ;
15
+ use Illuminate \Support \Collection ;
16
16
use Illuminate \Support \Facades \File ;
17
17
18
18
/**
@@ -39,7 +39,7 @@ public function __construct(OutputStyle $output)
39
39
40
40
public function compileStaticPages (): void
41
41
{
42
- $ this ->getDiscoveredModels ()->each (function (string $ pageClass ) {
42
+ $ this ->getClassNamesForDiscoveredPageModels ()->each (function (string $ pageClass ) {
43
43
$ this ->compilePagesForClass ($ pageClass );
44
44
});
45
45
}
@@ -60,51 +60,42 @@ public function transferMediaAssets(): void
60
60
{
61
61
$ this ->needsDirectory (Hyde::sitePath ('media ' ));
62
62
63
- $ collection = DiscoveryService::getMediaAssetFiles ();
64
63
$ this ->comment ('Transferring Media Assets... ' );
65
64
66
- $ this ->withProgressBar (
67
- $ collection ,
68
- function ($ filepath ) {
69
- copy ($ filepath , Hyde::sitePath ('media/ ' .basename ($ filepath )));
70
- }
71
- );
65
+ $ this ->withProgressBar (DiscoveryService::getMediaAssetFiles (), function (string $ filepath ): void {
66
+ copy ($ filepath , Hyde::sitePath ('media/ ' .basename ($ filepath )));
67
+ });
68
+
72
69
$ this ->newLine (2 );
73
70
}
74
71
75
72
/**
76
- * @return \Hyde\Foundation\RouteCollection <array-key, class-string<\Hyde\Pages\Concerns\HydePage>>
73
+ * @return \Illuminate\Support\Collection <array-key, class-string<\Hyde\Pages\Concerns\HydePage>>
77
74
*/
78
- protected function getDiscoveredModels (): RouteCollection
75
+ protected function getClassNamesForDiscoveredPageModels (): Collection
79
76
{
80
- return $ this ->router ->getRoutes ()->map (function (Route $ route ) {
77
+ return $ this ->router ->getRoutes ()->map (function (Route $ route ): string {
81
78
return $ route ->getPageClass ();
82
79
})->unique ();
83
80
}
84
81
82
+ /**
83
+ * @param class-string<\Hyde\Pages\Concerns\HydePage> $pageClass
84
+ */
85
85
protected function compilePagesForClass (string $ pageClass ): void
86
86
{
87
- $ this ->comment ("Creating {$ this ->getModelPluralName ($ pageClass )}... " );
87
+ $ this ->comment ("Creating {$ this ->getClassPluralName ($ pageClass )}... " );
88
88
89
89
$ collection = $ this ->router ->getRoutes ($ pageClass );
90
90
91
- $ this ->withProgressBar (
92
- $ collection ,
93
- $ this ->compileRoute ()
94
- );
91
+ $ this ->withProgressBar ($ collection , function (Route $ route ): void {
92
+ (new StaticPageBuilder ($ route ->getPage ()))->__invoke ();
93
+ });
95
94
96
95
$ this ->newLine (2 );
97
96
}
98
97
99
- /** @psalm-return \Closure(\Hyde\Support\Models\Route):string */
100
- protected function compileRoute (): Closure
101
- {
102
- return function (Route $ route ) {
103
- return (new StaticPageBuilder ($ route ->getPage ()))->__invoke ();
104
- };
105
- }
106
-
107
- protected function getModelPluralName (string $ pageClass ): string
98
+ protected function getClassPluralName (string $ pageClass ): string
108
99
{
109
100
return preg_replace ('/([a-z])([A-Z])/ ' , '$1 $2 ' , class_basename ($ pageClass )).'s ' ;
110
101
}
@@ -122,10 +113,7 @@ protected function isItSafeToCleanOutputDirectory(): bool
122
113
123
114
protected function isOutputDirectoryWhitelisted (): bool
124
115
{
125
- return in_array (
126
- basename (Hyde::sitePath ()),
127
- config ('hyde.safe_output_directories ' , ['_site ' , 'docs ' , 'build ' ])
128
- );
116
+ return in_array (basename (Hyde::sitePath ()), $ this ->safeOutputDirectories ());
129
117
}
130
118
131
119
protected function askIfUnsafeDirectoryShouldBeEmptied (): bool
@@ -136,4 +124,9 @@ protected function askIfUnsafeDirectoryShouldBeEmptied(): bool
136
124
Site::$ outputPath
137
125
));
138
126
}
127
+
128
+ protected function safeOutputDirectories (): array
129
+ {
130
+ return config ('hyde.safe_output_directories ' , ['_site ' , 'docs ' , 'build ' ]);
131
+ }
139
132
}
0 commit comments