-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathDocsController.php
More file actions
49 lines (37 loc) · 1.36 KB
/
DocsController.php
File metadata and controls
49 lines (37 loc) · 1.36 KB
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
<?php
namespace App\Http\Controllers;
use App\Support\Documentation;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
class DocsController extends Controller
{
protected const DEFAULT_PAGE = 'installation';
protected const EXCLUDED = ['readme', 'license'];
/**
* Handle the incoming request.
*
* @return Application|Factory|View|RedirectResponse
*/
public function __invoke(Documentation $docs, ?string $page = null)
{
if ($page === null) {
return redirect()->route('docs', [self::DEFAULT_PAGE]);
}
$isMarkdown = str($page)->endsWith('.md');
$page = str($page)->replace('.md', '')->toString();
if (! $docs->exists(config('site.defaultVersion'), $page) || in_array($page, self::EXCLUDED)) {
abort(404);
}
$index = $docs->getIndex(config('site.defaultVersion'));
$document = $docs->get(config('site.defaultVersion'), $page);
$matter = $document['matter'];
$markdown = $document['markdown'];
$body = $document['html'];
if ($isMarkdown) {
return response($markdown, 200, ['Content-Type' => 'text/plain']);
}
return view('docs', compact('body', 'matter', 'markdown', 'page', 'index'));
}
}