-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap.php
75 lines (61 loc) · 2.07 KB
/
bootstrap.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
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use TightenCo\Jigsaw\Jigsaw;
/** @var \Illuminate\Container\Container $container */
/** @var \TightenCo\Jigsaw\Events\EventBus $events */
if (class_exists("Dotenv\Dotenv")) {
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
}
/*
* You can run custom code at different stages of the build process by
* listening to the 'beforeBuild', 'afterCollections', and 'afterBuild' events.
*
* For example:
*
* $events->beforeBuild(function (Jigsaw $jigsaw) {
* // Your code here
* });
*/
$events->beforeBuild(function (Jigsaw $jigsaw) {
$changelog = Http::get("https://raw.githubusercontent.com/julienbourdeau/debugbar/master/CHANGELOG.md")->body();
$headers = <<<TEXT
---
extends: _layouts.changelog
section: content
slug: changelog
title: Changelog
subtitle: "What's new in Debugbar?"
seo_title: "Rails Debugbar Changelog"
seo_description: "All new features, improvements and fixes in Debugbar and more importantly: all the breaking changes!"
---
TEXT;
$content = $headers ."\n\n". $changelog;
File::put(__DIR__.'/source/changelog.blade.md', $content);
});
$events->afterBuild(function (Jigsaw $jigsaw) {
exec('git checkout -- '.__DIR__.'/source/changelog.blade.md');
});
$events->beforeBuild(function (Jigsaw $jigsaw) {
$files = glob(__DIR__.'/source/assets/debugbar/*.js');
if (count($files) !== 1) {
echo "\n\nToo many demo files found in source/assets/debugbar\n\n";
exit(1);
}
$jigsaw->setConfig('debugbarAssets', [
'js' => basename($files[0]),
]);
});
$events->afterCollections(function (Jigsaw $jigsaw) {
global $docsToc; // YOLO
$docsToc = $jigsaw->getCollection('docs')->map(function ($page) {
return [
'title' => $page->title,
'section' => $page->toc_section,
'url' => $page->getPath(),
'disabled' => $page->disabled ?? false,
];
})->values()->groupBy('section');
});
\Torchlight\Jigsaw\TorchlightExtension::make($container, $events)->boot();