|
4 | 4 |
|
5 | 5 | use Carbon\Carbon; |
6 | 6 | use DateTimeInterface; |
| 7 | +use Illuminate\Contracts\Filesystem\FileNotFoundException; |
7 | 8 | use Illuminate\Support\Arr; |
8 | 9 | use Illuminate\Support\Collection; |
9 | 10 | use Illuminate\Support\Facades\File; |
@@ -189,25 +190,43 @@ public function script(): HtmlString |
189 | 190 |
|
190 | 191 | protected function cookiePolicyText(string $locale): ?string |
191 | 192 | { |
192 | | - if (File::exists(resource_path(sprintf('views/vendor/cookie-solution/policy/cookie-policy.%s.md', $locale)))) { |
193 | | - return Str::markdown(File::get(resource_path(sprintf('views/vendor/cookie-solution/policy/cookie-policy.%s.md', $locale))), $this->markdownConfig); |
194 | | - } |
| 193 | + $paths = [ |
| 194 | + resource_path(sprintf('views/vendor/cookie-solution/policy/cookie-policy.%s.md', $locale)), |
| 195 | + __DIR__.sprintf('/../resources/views/policy/cookie-policy.%s.md', $locale), |
| 196 | + ]; |
195 | 197 |
|
196 | | - if (File::exists(__DIR__.sprintf('/../resources/views/policy/cookie-policy.%s.md', $locale))) { |
197 | | - return Str::markdown(File::get(__DIR__.sprintf('/../resources/views/policy/cookie-policy.%s.md', $locale)), $this->markdownConfig); |
| 198 | + foreach ($paths as $path) { |
| 199 | + if (! File::exists($path)) { |
| 200 | + continue; |
| 201 | + } |
| 202 | + |
| 203 | + try { |
| 204 | + return $this->renderMarkdownFile($path); |
| 205 | + } catch (FileNotFoundException) { |
| 206 | + continue; |
| 207 | + } |
198 | 208 | } |
199 | 209 |
|
200 | 210 | return null; |
201 | 211 | } |
202 | 212 |
|
203 | 213 | protected function privacyPolicyText(string $locale): ?string |
204 | 214 | { |
205 | | - if (File::exists(resource_path(sprintf('views/vendor/cookie-solution/policy/privacy-policy.%s.md', $locale)))) { |
206 | | - return Str::markdown(File::get(resource_path(sprintf('views/vendor/cookie-solution/policy/privacy-policy.%s.md', $locale))), $this->markdownConfig); |
207 | | - } |
| 215 | + $paths = [ |
| 216 | + resource_path(sprintf('views/vendor/cookie-solution/policy/privacy-policy.%s.md', $locale)), |
| 217 | + __DIR__.sprintf('/../resources/views/policy/privacy-policy.%s.md', $locale), |
| 218 | + ]; |
208 | 219 |
|
209 | | - if (File::exists(__DIR__.sprintf('/../resources/views/policy/privacy-policy.%s.md', $locale))) { |
210 | | - return Str::markdown(File::get(__DIR__.sprintf('/../resources/views/policy/privacy-policy.%s.md', $locale)), $this->markdownConfig); |
| 220 | + foreach ($paths as $path) { |
| 221 | + if (! File::exists($path)) { |
| 222 | + continue; |
| 223 | + } |
| 224 | + |
| 225 | + try { |
| 226 | + return $this->renderMarkdownFile($path); |
| 227 | + } catch (FileNotFoundException) { |
| 228 | + continue; |
| 229 | + } |
211 | 230 | } |
212 | 231 |
|
213 | 232 | return null; |
@@ -255,4 +274,23 @@ protected function configDigest(): string |
255 | 274 |
|
256 | 275 | return hash('sha256', $cookies); |
257 | 276 | } |
| 277 | + |
| 278 | + /** |
| 279 | + * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
| 280 | + */ |
| 281 | + protected function renderMarkdownFile(string $sourcePath): string |
| 282 | + { |
| 283 | + $cachePath = storage_path(sprintf('framework/views/%s.html', hash('xxh128', $sourcePath))); |
| 284 | + |
| 285 | + if (File::exists($cachePath) && File::lastModified($cachePath) >= File::lastModified($sourcePath)) { |
| 286 | + return File::get($cachePath); |
| 287 | + } |
| 288 | + |
| 289 | + $content = Str::markdown(File::get($sourcePath)); |
| 290 | + |
| 291 | + File::ensureDirectoryExists(dirname($cachePath)); |
| 292 | + File::put($cachePath, $content); |
| 293 | + |
| 294 | + return $content; |
| 295 | + } |
258 | 296 | } |
0 commit comments