Skip to content

Commit 4c42c63

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

File tree

15 files changed

+212
-117
lines changed

15 files changed

+212
-117
lines changed

app/Console/Commands/CompareDocument.php

Lines changed: 1 addition & 1 deletion
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

Lines changed: 33 additions & 23 deletions
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

Lines changed: 13 additions & 5 deletions
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

Lines changed: 9 additions & 13 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/app-C5tVmPJ2.css

Lines changed: 0 additions & 5 deletions
This file was deleted.

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

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/manifest.json

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
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,

0 commit comments

Comments
 (0)