Skip to content

Commit 2f5c4b7

Browse files
agoalofalifetabuna
authored andcommitted
добавление функционала по поиску
1 parent 8ddfd02 commit 2f5c4b7

File tree

7 files changed

+48
-14
lines changed

7 files changed

+48
-14
lines changed

app/Docs.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class Docs
2525
* Array of supported versions
2626
*/
2727
public const SUPPORT_VERSIONS = [
28-
'11.x',
2928
'10.x',
3029
'8.x',
3130
'5.4',
@@ -373,9 +372,13 @@ public function getSections(): Collection
373372
$sections = collect();
374373
$prevEnd = 0;
375374

375+
$titlePage = null;
376376
foreach ($matches as $index => $match) {
377377
$sectionTitle = $match[2];
378378

379+
if ($match[1] == '1') {
380+
$titlePage = $sectionTitle;
381+
}
379382
// Получаем начальную и конечную позицию текущего заголовка в тексте
380383
$startPos = strpos($this->content(), $match[0], $prevEnd);
381384

@@ -389,12 +392,13 @@ public function getSections(): Collection
389392
}
390393

391394
$sections->push([
392-
'title' => $sectionTitle,
393-
'slug' => Str::of($sectionTitle)->slug()->toString(),
394-
'content' => $sectionContent,
395-
'file' => $this->file,
396-
'version' => $this->version,
397-
'id' => Str::uuid(),
395+
'title_page' => $titlePage,
396+
'title' => $sectionTitle,
397+
'slug' => Str::of($sectionTitle)->slug()->toString(),
398+
'content' => $sectionContent,
399+
'file' => $this->file,
400+
'version' => $this->version,
401+
'id' => Str::uuid(),
398402
]);
399403
}
400404

@@ -403,7 +407,7 @@ public function getSections(): Collection
403407

404408
public function updateSections()
405409
{
406-
// DocumentationSection::where('file', $this->file)->where('version', $this->version)->delete();
407-
// DocumentationSection::insert($this->getSections()->toArray());
410+
DocumentationSection::where('file', $this->file)->where('version', $this->version)->delete();
411+
DocumentationSection::insert($this->getSections()->toArray());
408412
}
409413
}

app/Models/DocumentationSection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ protected function shortContent(): Attribute
3333
{
3434

3535
return Attribute::make(
36-
get: fn (mixed $value, array $attributes) => Str::limit(
36+
get: fn (mixed $value, array $attributes) =>
37+
38+
Str::limit(
3739
nl2br(strip_tags($attributes['content'])),
3840
90
3941
),

database/migrations/2024_03_17_133145_create_documentation_sections_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Illuminate\Database\Migrations\Migration;
44
use Illuminate\Database\Schema\Blueprint;
55
use Illuminate\Support\Facades\Schema;
6+
use Illuminate\Support\Str;
67

78
return new class extends Migration
89
{

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Controller } from '@hotwired/stimulus';
22

33
export default class extends Controller {
4-
static targets = ['text', 'spinner'];
4+
static targets = [ "text", "spinner"]
55
/**
66
* Port for laravel.com
77
*/
88
connect() {}
99
search(event) {
1010
this.spinnerTarget.classList.remove('d-none');
1111
event.target.form.requestSubmit();
12-
setTimeout(() => this.spinnerTarget.classList.add('d-none'), 500);
12+
setTimeout(() => this.spinnerTarget.classList.add('d-none'), 500)
1313
}
1414
}

resources/views/docs/docs.blade.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,31 @@
77
<div class="row gap-2 justify-content-center align-items-start position-relative mb-5">
88
<div class="col-3 col-xl-3 col-xxl-2 order-md-first order-last position-sticky top-0 py-md-3 z-1 d-none d-lg-block doc-navigation">
99

10-
<div class="mb-md-4 ms-md-4 d-flex align-items-stretch flex-column offcanvas-md offcanvas-start" id="docs-menu">
10+
<div class="mb-md-4 ms-md-4 d-flex align-items-stretch flex-column offcanvas-md offcanvas-start" id="docs-menu"
11+
data-controller="search-docs"
12+
>
13+
<div>
14+
<div class="mb-3">
15+
<span data-search-docs-target="spinner" class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
16+
<form action="{{ route('docs.search', ['versionOfDocs' => $docs->version]) }}" method="post" id="search-form">
17+
@csrf
18+
<input class="form-control form-control-md"
19+
data-action="input->search-docs#search"
20+
name="text"
21+
data-search-docs-target="text"
22+
type="text" placeholder="Поиск по документации..." aria-label=".form-control-lg example">
23+
</form>
24+
{{-- <template>--}}
25+
<div class="mt-2" >
26+
@include('docs._search_lines', ['searchOffer' => []])
27+
{{-- <ul class="list-group">--}}
28+
{{-- <li class="list-group-item">Курс по Laravel (Laravel Bootcamp)</li>--}}
29+
{{-- <li class="list-group-item">Значения атрибутов по умолчанию</li>--}}
30+
{{-- </ul>--}}
31+
</div>
32+
{{-- </template>--}}
33+
</div>
34+
</div>
1135

1236
{{--
1337
<input class="form-control form-control-lg" type="text" placeholder="Поиск по документации..."

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
Route::post('/docs/{versionOfDocs}/search', [DocsController::class, 'search'])->name('docs.search');
381381
Route::get('/docs/{page}', fn (string $page) => redirect()->route('docs', ['version' => Docs::DEFAULT_VERSION, 'page' => $page]));
382382

383+
383384
Route::get('nav/docs/{version?}', [DocsController::class, 'navigation'])
384385
->whereIn('version', Docs::SUPPORT_VERSIONS)
385386
->name('nav.docs');

0 commit comments

Comments
 (0)