Skip to content

Commit 4c42c63

Browse files
committed
Changed detect sections
Changed UI
1 parent 2f5c4b7 commit 4c42c63

15 files changed

+212
-117
lines changed

app/Console/Commands/CompareDocument.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function updateVersion(string $version): void
4242
{
4343
Docs::every($version)->each(function (Docs $docs) {
4444
try {
45-
$docs->update();
45+
dispatch(fn() => $docs->update());
4646
} catch (\Exception $exception) {
4747
// Log a warning if an error occurs during update
4848
$this->warn("Failed to update document: {$exception->getMessage()} {$exception->getFile()} {$exception->getLine()}");

app/Docs.php

+33-23
Original file line numberDiff line numberDiff line change
@@ -348,14 +348,13 @@ public function isOlderVersion()
348348
*/
349349
public function update()
350350
{
351-
352351
$this->getModel()->fill([
353352
'behind' => $this->fetchBehind(),
354353
'last_commit' => $this->fetchLastCommit(),
355354
'current_commit' => $this->variables('git'),
356355
])->save();
357356

358-
// $this->updateSections();
357+
$this->updateSections();
359358
}
360359

361360
/**
@@ -365,49 +364,60 @@ public function update()
365364
*/
366365
public function getSections(): Collection
367366
{
367+
$content = Str::of($this->content());
368+
368369
// Разбиваем HTML содержимое на разделы по заголовкам
369-
preg_match_all('/<h(\d)>(.+)<\/h\d>(.*)/sU', $this->content(), $matches, PREG_SET_ORDER);
370+
preg_match_all('/<h(\d)>(.+)<\/h\d>(.*)/sU', $content->toString(), $matches, PREG_SET_ORDER);
370371

371372
// Массив для хранения разделов
372373
$sections = collect();
373-
$prevEnd = 0;
374+
$titlePage = $this->title();
374375

375-
$titlePage = null;
376376
foreach ($matches as $index => $match) {
377+
$tag = $match[0];
378+
$level = (int) $match[1];
377379
$sectionTitle = $match[2];
378380

379-
if ($match[1] == '1') {
381+
if ($level === 1) {
380382
$titlePage = $sectionTitle;
381383
}
382-
// Получаем начальную и конечную позицию текущего заголовка в тексте
383-
$startPos = strpos($this->content(), $match[0], $prevEnd);
384-
385-
// Получаем текст между текущим и предыдущим заголовком
386-
if ($index > 0) {
387-
$prevMatch = $matches[$index - 1];
388-
$prevEnd = strpos($this->content(), $prevMatch[0]) + strlen($prevMatch[0]);
389-
$sectionContent = substr($this->content(), $prevEnd, $startPos - $prevEnd);
390-
} else {
391-
$sectionContent = substr($this->content(), 0, $startPos);
384+
385+
$sectionContent = $content->after($tag);
386+
387+
if (isset($matches[$index + 1])) {
388+
$sectionContent = $sectionContent->before($matches[$index + 1][0]);
392389
}
393390

394391
$sections->push([
395392
'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(),
393+
'title' => $sectionTitle,
394+
'slug' => Str::of($sectionTitle)->slug()->toString(),
395+
'content' => $sectionContent,
396+
'file' => $this->file,
397+
'version' => $this->version,
398+
'id' => Str::uuid(),
399+
'level' => $level,
400+
'created_at' => now(),
401+
'updated_at' => now(),
402402
]);
403403
}
404404

405405
return $sections;
406406
}
407407

408+
/**
409+
* @return void
410+
*/
408411
public function updateSections()
409412
{
410-
DocumentationSection::where('file', $this->file)->where('version', $this->version)->delete();
413+
if ($this->file === 'documentation.md') {
414+
return;
415+
}
416+
417+
DocumentationSection::where('file', $this->file)
418+
->where('version', $this->version)
419+
->delete();
420+
411421
DocumentationSection::insert($this->getSections()->toArray());
412422
}
413423
}

app/Http/Controllers/DocsController.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,23 @@ public function status(string $version = Docs::DEFAULT_VERSION)
6161
]);
6262
}
6363

64+
/**
65+
* @param string $versionOfDocs
66+
* @param \Illuminate\Http\Request $request
67+
*
68+
* @return \HotwiredLaravel\TurboLaravel\Http\MultiplePendingTurboStreamResponse|\HotwiredLaravel\TurboLaravel\Http\PendingTurboStreamResponse
69+
*/
6470
public function search(string $versionOfDocs, Request $request)
6571
{
72+
$searchOffers = [];
6673

67-
if (empty($request->text)) {
68-
return turbo_stream()->replace('found_candidates', view('docs._search_lines', [
69-
'searchOffer' => [],
70-
]));
74+
if ($request->filled('text')) {
75+
$searchOffers = DocumentationSection::search($request->text)
76+
->where('version', $versionOfDocs)
77+
->orderBy('level')
78+
->get()
79+
->take(6);
7180
}
72-
$searchOffers = DocumentationSection::search($request->text)->where('version', $versionOfDocs)->get();
7381

7482
return turbo_stream()->replace('found_candidates', view('docs._search_lines', [
7583
'searchOffer' => $searchOffers,

app/Models/DocumentationSection.php

+9-13
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,33 @@ class DocumentationSection extends Model
2323
protected $fillable = [
2424
'id',
2525
'title',
26+
'title_page',
2627
'slug',
2728
'version',
2829
'file',
2930
'content',
31+
'level',
3032
];
3133

32-
protected function shortContent(): Attribute
33-
{
34-
35-
return Attribute::make(
36-
get: fn (mixed $value, array $attributes) =>
37-
38-
Str::limit(
39-
nl2br(strip_tags($attributes['content'])),
40-
90
41-
),
42-
);
43-
}
44-
34+
/**
35+
* @return \Illuminate\Database\Eloquent\Casts\Attribute
36+
*/
4537
protected function fileForUrl(): Attribute
4638
{
4739
return Attribute::make(
4840
get: fn (mixed $value, array $attributes) => str_replace('.md', '', $attributes['file']),
4941
);
5042
}
5143

44+
/**
45+
* @return array
46+
*/
5247
public function toSearchableArray()
5348
{
5449
return [
5550
'title' => $this->title,
5651
'content' => $this->content,
52+
'level' => $this->level,
5753
];
5854
}
5955
}

database/migrations/2024_03_17_133145_create_documentation_sections_table.php

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function up(): void
1616
$table->uuid('id')->primary();
1717
$table->string('title_page')->comment('Заголовок всей страницы');
1818
$table->string('title');
19+
$table->integer('level')->nullable()->comment('Уровень заголовка');
1920
$table->string('slug');
2021
$table->string('version');
2122
$table->string('file');

public/build/assets/app-BUWIDZ8f.js renamed to public/build/assets/app-B-hWsIbj.js

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/app-C5tVmPJ2.css

-5
This file was deleted.

public/build/assets/app-jsXsVF-0.css

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"src": "public/img/ui/warning.svg"
1313
},
1414
"resources/css/app.scss": {
15-
"file": "assets/app-C5tVmPJ2.css",
15+
"file": "assets/app-jsXsVF-0.css",
1616
"src": "resources/css/app.scss",
1717
"isEntry": true
1818
},
1919
"resources/js/app.js": {
20-
"file": "assets/app-CnjHucs5.js",
20+
"file": "assets/app-B-hWsIbj.js",
2121
"src": "resources/js/app.js",
2222
"isEntry": true,
2323
"css": [

resources/css/app.scss

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ $input-padding-x: 1rem;
6868

6969
$badge-font-weight: normal;
7070

71+
$modal-backdrop-opacity: 0.675;
72+
7173
$utilities: (
7274
'line-clamp': (
7375
property: -webkit-line-clamp,

resources/css/docs.scss

+11
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,14 @@ main,
399399
max-width: 1680px;
400400
margin: 0 auto;
401401
}
402+
403+
404+
.docs-result-item {
405+
max-height: 300px;
406+
407+
.main {
408+
blockquote {
409+
display: none !important;
410+
}
411+
}
412+
}

resources/css/reset.scss

+18
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,28 @@ img {
7979
img {
8080
color-scheme: light !important;
8181
}
82+
83+
.modal-backdrop {
84+
--bs-backdrop-bg: #fff !important;
85+
}
8286
}
8387

8488
@include color-mode(dark) {
8589
img {
8690
color-scheme: dark !important;
8791
}
92+
93+
.modal-backdrop {
94+
--bs-backdrop-bg: #000 !important;
95+
}
96+
}
97+
98+
99+
100+
.modal-sheet .modal-dialog {
101+
width: 480px;
102+
transition: bottom .75s ease-in-out;
103+
}
104+
.modal-sheet .modal-footer {
105+
padding-bottom: 2rem;
88106
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
import { Controller } from '@hotwired/stimulus';
1+
import {Controller} from '@hotwired/stimulus';
22

33
export default class extends Controller {
4-
static targets = [ "text", "spinner"]
5-
/**
6-
* Port for laravel.com
7-
*/
8-
connect() {}
9-
search(event) {
10-
this.spinnerTarget.classList.remove('d-none');
11-
event.target.form.requestSubmit();
12-
setTimeout(() => this.spinnerTarget.classList.add('d-none'), 500)
4+
static targets = ['text'];
5+
6+
initialize() {
7+
this.intersectionObserver = new IntersectionObserver((entries) => this.processIntersectionEntries(entries));
8+
}
9+
10+
connect() {
11+
this.intersectionObserver.observe(this.element);
12+
}
13+
14+
disconnect() {
15+
this.intersectionObserver.unobserve(this.element);
16+
}
17+
18+
processIntersectionEntries(entries) {
19+
entries.forEach((entry) => {
20+
this.textTarget.focus();
21+
});
22+
}
23+
24+
search() {
25+
clearTimeout(this.timeout)
26+
this.timeout = setTimeout(() => {
27+
this.textTarget.form.requestSubmit();
28+
}, 340)
1329
}
1430
}
+45-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,48 @@
1-
<ul class="list-group" id="found_candidates">
2-
@foreach($searchOffer as $offer)
3-
{{-- <li class="list-group-item fs-6 text fw-bold" style="font-size: 14px !important;">{{ $offer->title_page }}</li>--}}
1+
<ul class="d-grid gap-4 mt-5 mb-0 list-unstyled" id="found_candidates">
2+
@forelse($searchOffer as $offer)
3+
<li class="position-relative overflow-hidden docs-result-item">
4+
<a href="{{ route('docs', ['version' => $offer->version, 'page' => "{$offer->file_for_url}#{$offer->slug}" ]) }}"
5+
class="stretched-link"></a>
46

5-
<a href="{{ route('docs', ['version' => $offer->version, 'page' => "{$offer->file_for_url}#{$offer->slug}" ]) }}" class="list-group-item list-group-item-action" aria-current="true">
6-
<div class="d-flex w-100 justify-content-between">
7-
<p class="mb-1 fw-bold font-monospace">{{ $offer->title_page }}</p>
8-
{{-- <small>3 days ago</small>--}}
9-
</div>
10-
{{-- @dd(Str::of($offer->content)->limit(20)->__toString())--}}
11-
<p class="mb-1">{{ $offer->title }}</p>
12-
<small>{!! $offer->short_content !!}</small>
7+
<p class="mb-1 fw-bold font-monospace small text-primary">{{ $offer->title_page }}</p>
8+
<p class="h5 mb-2">{!! $offer->title !!}</p>
9+
<div class="small line-clamp line-clamp-4 opacity-75 main">{!! $offer->content !!}</div>
10+
</li>
1311

14-
</a>
15-
@endforeach
16-
</ul>
12+
@if(!$loop->last)
13+
<li class=""><hr class="my-1"></li>
14+
@endif
15+
@empty
16+
<li class="d-flex gap-4">
17+
<small class="text-primary">Смотрите так же:</small>
18+
</li>
19+
20+
<li class="d-flex gap-4 position-relative">
21+
<x-icon path="i.files" class="text-body-secondary flex-shrink-0 mt-1" width="1.5rem" height="1.5rem"/>
22+
<div>
23+
<h5 class="mb-0">Ищите работу?</h5>
24+
<small class="opacity-75">Посмотрите раздел вакансии с самыми вкусными предложениями на рынке.</small>
25+
</div>
26+
27+
<a href="{{ route('jobs') }}" class="stretched-link"></a>
28+
</li>
29+
<li class="d-flex gap-4 position-relative">
30+
<x-icon path="i.orchid" class="text-body-secondary flex-shrink-0 mt-1" width="1.5rem" height="1.5rem"/>
31+
<div>
32+
<h5 class="mb-0">Orchid</h5>
33+
<small class="opacity-75">Создавайте админ панели и внутренние бизнес системы основанные на PHP коде.</small>
34+
</div>
1735

36+
<a href="{{ route('orchid') }}" class="stretched-link"></a>
37+
</li>
38+
<li class="d-flex gap-4 position-relative">
39+
<x-icon path="i.code" class="text-body-secondary flex-shrink-0 mt-1" width="1.5rem" height="1.5rem"/>
40+
<div>
41+
<h5 class="mb-0">Pastebin</h5>
42+
<small class="opacity-75">Делитесь своим кодом правильно, ни кто не любит простыню текста в сообщениях.</small>
43+
</div>
44+
45+
<a href="{{ route('pastebin') }}" class="stretched-link"></a>
46+
</li>
47+
@endforelse
48+
</ul>

0 commit comments

Comments
 (0)