Skip to content

Commit

Permalink
💄 Show the current doc page sections in the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x committed Feb 8, 2024
1 parent 853f419 commit edf09c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/Livewire/Docs/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public function render()
$menu[$doc->group][] = [
'title' => $doc->title,
'slug' => $doc->slug,
'sections' => request()->url() === route('docs.show', [$doc->slug])
? collect(explode("\n", $doc->content))
->filter(fn ($line) => Str::startsWith($line, '## '))
->map(fn ($line) => Str::after($line, '## '))
->mapWithKeys(fn ($section) => [$section => Str::slug($section)])
->map(fn ($section) => "#content-{$section}")
->toArray()
: [],
];
}

Expand Down
12 changes: 12 additions & 0 deletions resources/views/livewire/docs/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@

{{ $item['title'] }}
</a>

@if ($item['sections'])
<ul class="mt-1 mb-4 ml-6 space-y-2 text-sm">
@foreach ($item['sections'] as $label => $value)
<li>
<a href="{{ $value }}" class="transition text-white/35 hover:text-primary-500">
{{ $label }}
</a>
</li>
@endforeach
</ul>
@endif
</li>
@endforeach
</ul>
Expand Down

0 comments on commit edf09c6

Please sign in to comment.