Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions app/Docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,24 +232,25 @@ public function docsToArray(string $html): array
$crawler = new Crawler;
$crawler->addContent($html);

$crawler = new Crawler($html);

$menu = [];

$crawler->filter('ul > li')->each(function (Crawler $node) use (&$menu) {
$crawler->filter('body > ul > li')->each(function (Crawler $node) use (&$menu) {
$subList = $node->filter('ul > li')->each(fn (Crawler $subNode) => [
'title' => $subNode->filter('a')->text(),
'href' => url($subNode->filter('a')->attr('href')),
]);

if (empty($subList)) {
return null;
$menu[] = [
'title' => $node->filter('a')->text(),
'href' => url($node->filter('a')->attr('href')),
];
} else {
$menu[] = [
'title' => $node->filter('h2')->text(),
'list' => $subList,
];
}

$menu[] = [
'title' => $node->filter('h2')->text(),
'list' => $subList,
];
});

return $menu;
Expand Down
51 changes: 29 additions & 22 deletions resources/views/docs/docs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,35 @@
<ul class="list-unstyled p-4 px-md-0">
@foreach ($docs->getMenu() as $item)
<li class="mb-2">
<button
class="btn btn-toggle d-flex align-items-center rounded border-0 collapsed text-body-secondary p-0 w-100 text-start"
data-bs-toggle="collapse"
data-bs-target="#{{ \Illuminate\Support\Str::slug($item['title']) }}-collapse"
aria-expanded="true">
{{ $item['title'] }}
</button>

<div class="collapse {{ active(collect($item['list'])->map(fn($link) => $link['href']), 'show') }} mt-2"
id="{{ \Illuminate\Support\Str::slug($item['title']) }}-collapse"
data-bs-parent="#docs-menu">
<ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small ms-2">
@foreach ($item['list'] as $link)
<li>
<a href="{{ $link['href'] }}"
class="{{ active(url($link['href']), 'active', 'link-body-emphasis') }} d-inline-flex text-decoration-none rounded p-2">
{{ $link['title'] }}
</a>
</li>
@endforeach
</ul>
</div>
@if (!empty($item['list']))
<button
class="btn btn-toggle d-flex align-items-center rounded border-0 collapsed text-body-secondary p-0 w-100 text-start"
data-bs-toggle="collapse"
data-bs-target="#{{ \Illuminate\Support\Str::slug($item['title']) }}-collapse"
aria-expanded="true">
{{ $item['title'] }}
</button>

<div class="collapse {{ active(collect($item['list'])->map(fn($link) => $link['href']), 'show') }} mt-2"
id="{{ \Illuminate\Support\Str::slug($item['title']) }}-collapse"
data-bs-parent="#docs-menu">
<ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small ms-2">
@foreach ($item['list'] as $link)
<li>
<a href="{{ $link['href'] }}"
class="{{ active(url($link['href']), 'active', 'link-body-emphasis') }} d-inline-flex text-decoration-none rounded p-2">
{{ $link['title'] }}
</a>
</li>
@endforeach
</ul>
</div>
@else
<a href="{{ $item['href'] }}"
class="btn btn-toggle d-flex align-items-center rounded border-0 collapsed text-body-secondary p-0 w-100 text-start">
{{ $item['title'] }}
</a>
@endif
</li>
@endforeach
</ul>
Expand Down
49 changes: 28 additions & 21 deletions resources/views/docs/navigation.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,35 @@

@foreach ($docs->getMenu() as $item)
<li class="{{ $loop->last ? '' : 'mb-4' }}">
<button
class="btn btn-toggle d-flex align-items-center rounded border-0 collapsed fw-medium fs-4 text-body-secondary p-0 w-100 text-start"
data-bs-toggle="collapse"
data-bs-target="#{{ \Illuminate\Support\Str::slug($item['title']) }}-collapse"
aria-expanded="true">
{{ $item['title'] }}
</button>
@if (!empty($item['list']))
<button
class="btn btn-toggle d-flex align-items-center rounded border-0 collapsed fw-medium fs-4 text-body-secondary p-0 w-100 text-start"
data-bs-toggle="collapse"
data-bs-target="#{{ \Illuminate\Support\Str::slug($item['title']) }}-collapse"
aria-expanded="true">
{{ $item['title'] }}
</button>

<div class="collapse {{ active(collect($item['list'])->map(fn($link) => $link['href']), 'show') }} mt-2"
id="{{ \Illuminate\Support\Str::slug($item['title']) }}-collapse"
data-bs-parent="#docs-menu">
<ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small ms-2">
@foreach ($item['list'] as $link)
<li>
<a href="{{ $link['href'] }}"
class="{{ active(url($link['href']), 'active', 'link-body-emphasis') }} d-inline-flex text-decoration-none rounded p-2">
{{ $link['title'] }}
</a>
</li>
@endforeach
</ul>
</div>
<div class="collapse {{ active(collect($item['list'])->map(fn($link) => $link['href']), 'show') }} mt-2"
id="{{ \Illuminate\Support\Str::slug($item['title']) }}-collapse"
data-bs-parent="#docs-menu">
<ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small ms-2">
@foreach ($item['list'] as $link)
<li>
<a href="{{ $link['href'] }}"
class="{{ active(url($link['href']), 'active', 'link-body-emphasis') }} d-inline-flex text-decoration-none rounded p-2">
{{ $link['title'] }}
</a>
</li>
@endforeach
</ul>
</div>
@else
<a href="{{ $item['href'] }}"
class="btn btn-toggle d-flex align-items-center rounded border-0 collapsed fw-medium fs-4 text-body-secondary p-0 w-100 text-start">
{{ $item['title'] }}
</a>
@endif
</li>
@endforeach

Expand Down
Loading