Skip to content

Commit 7ac8af1

Browse files
committed
Changed docs behind
1 parent bc21455 commit 7ac8af1

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

app/Console/Commands/CompareDocument.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use App\Docs;
66
use Illuminate\Console\Command;
7-
use Illuminate\Support\Facades\Http;
8-
use Illuminate\Support\Facades\Storage;
97

108
class CompareDocument extends Command
119
{
@@ -28,7 +26,7 @@ class CompareDocument extends Command
2826
*/
2927
public function handle()
3028
{
31-
collect(Docs::SUPPORT_VERSIONS)->each(fn(string $version) => $this->updateVersion($version));
29+
collect(Docs::SUPPORT_VERSIONS)->each(fn (string $version) => $this->updateVersion($version));
3230
}
3331

3432
/**

app/Docs.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Docs
2323
public const SUPPORT_VERSIONS = [
2424
'8.x',
2525
'5.4',
26-
'4.2'
26+
'4.2',
2727
];
2828

2929
/**
@@ -64,7 +64,7 @@ class Docs
6464
*/
6565
public function __construct(string $version, string $file)
6666
{
67-
$this->file = $file . '.md';
67+
$this->file = $file.'.md';
6868
$this->version = $version;
6969
$this->path = "/$version/$this->file";
7070

@@ -77,7 +77,7 @@ public function __construct(string $version, string $file)
7777

7878
try {
7979
$this->variables = Yaml::parse($variables);
80-
}catch (\Throwable){
80+
} catch (\Throwable) {
8181

8282
}
8383
}
@@ -87,9 +87,9 @@ public function __construct(string $version, string $file)
8787
*
8888
* @param string $view The view name.
8989
*
90-
* @return \Illuminate\Contracts\View\View The rendered view of the documentation page.
91-
*
9290
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
91+
*
92+
* @return \Illuminate\Contracts\View\View The rendered view of the documentation page.
9393
*/
9494
public function view(string $view)
9595
{
@@ -115,7 +115,7 @@ public function view(string $view)
115115
*/
116116
public function getMenu(): array
117117
{
118-
$page = Storage::disk('docs')->get($this->version . '/documentation.md');
118+
$page = Storage::disk('docs')->get($this->version.'/documentation.md');
119119

120120
$html = Str::of($page)
121121
->after('---')
@@ -156,7 +156,7 @@ public function docsToArray(string $html): array
156156
$menu = [];
157157

158158
$crawler->filter('ul > li')->each(function (Crawler $node) use (&$menu) {
159-
$subList = $node->filter('ul > li')->each(fn(Crawler $subNode) => [
159+
$subList = $node->filter('ul > li')->each(fn (Crawler $subNode) => [
160160
'title' => $subNode->filter('a')->text(),
161161
'href' => url($subNode->filter('a')->attr('href')),
162162
]);
@@ -181,15 +181,15 @@ public function docsToArray(string $html): array
181181
*
182182
* @return \Illuminate\Support\Collection A collection of Docs instances.
183183
*/
184-
static public function every(string $version): \Illuminate\Support\Collection
184+
public static function every(string $version): \Illuminate\Support\Collection
185185
{
186186
$files = Storage::disk('docs')->allFiles($version);
187187

188188
return collect($files)
189-
->filter(fn(string $path) => Str::of($path)->endsWith('.md'))
190-
->filter(fn(string $path) => !Str::of($path)->endsWith(['readme.md', 'license.md']))
191-
->map(fn(string $path) => Str::of($path)->after($version . '/')->before('.md'))
192-
->map(fn(string $path) => new static($version, $path));
189+
->filter(fn (string $path) => Str::of($path)->endsWith('.md'))
190+
->filter(fn (string $path) => ! Str::of($path)->endsWith(['readme.md', 'license.md']))
191+
->map(fn (string $path) => Str::of($path)->after($version.'/')->before('.md'))
192+
->map(fn (string $path) => new static($version, $path));
193193
}
194194

195195
/**
@@ -205,7 +205,7 @@ public function fetchBehind(): int
205205
->get("https://api.github.com/repos/laravel/docs/commits?sha={$this->version}&path={$this->file}");
206206

207207
return $response->collect()
208-
->takeUntil(fn($commit) => $commit['sha'] === $this->variables['git'])
208+
->takeUntil(fn ($commit) => $commit['sha'] === $this->variables['git'])
209209
->count();
210210
}
211211

@@ -237,11 +237,11 @@ public function goToOriginal(): string
237237
*
238238
* @return string
239239
*/
240-
static public function compareLink(string $version, string $hash): string
240+
public static function compareLink(string $version, string $hash): string
241241
{
242242
$compactHash = Str::of($hash)->limit(7, '')->toString();
243243

244-
return "https://github.com/laravel/docs/compare/$version..$compactHash";
244+
return "https://github.com/laravel/docs/compare/$compactHash..$version";
245245
}
246246

247247
/**
@@ -262,9 +262,9 @@ public function getModel(): Document
262262
}
263263

264264
/**
265-
* @return int
265+
* @return int|null
266266
*/
267-
public function behind():int
267+
public function behind(): ?int
268268
{
269269
return $this->getModel()->behind;
270270
}

app/Http/Controllers/DocsController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class DocsController extends Controller
1313
* @param string $version
1414
* @param string $page
1515
*
16-
* @return \Illuminate\View\View|
1716
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
17+
*
18+
* @return \Illuminate\View\View|
1819
*/
1920
public function show(string $version = Docs::DEFAULT_VERSION, string $page = 'installation')
2021
{
@@ -35,8 +36,8 @@ public function status(string $version = Docs::DEFAULT_VERSION)
3536
->get();
3637

3738
return view('pages.status', [
38-
'current' => $version,
39-
'documents' => $documents
39+
'current' => $version,
40+
'documents' => $documents,
4041
]);
4142
}
4243
}

app/Models/Document.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ class Document extends Model
2828
*/
2929
protected $attributes = [
3030
'version' => Docs::DEFAULT_VERSION,
31-
'behind' => 0,
31+
'behind' => null,
3232
];
3333
}

resources/views/pages/docs.blade.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,13 @@ class="{{ active(url($link['href']), 'active', 'link-body-emphasis') }} d-inline
5858

5959
<div class="d-grid gap-3 d-md-flex justify-content-md-end mb-3">
6060

61-
62-
@if ($docs->behind() > 0)
61+
@if($docs->behind() === null)
62+
<a href="{{ route('status', $docs->version) }}#{{ $docs->file }}" class="">
63+
<span class="badge bg-primary-subtle text-primary rounded rounded-1 fs-6 fw-normal">
64+
Перевод не имеет метки
65+
</span>
66+
</a>
67+
@elseif ($docs->behind() > 0)
6368
<a href="{{ route('status', $docs->version) }}#{{ $docs->file }}" class="">
6469
<span class="badge bg-primary-subtle text-primary rounded rounded-1 fs-6 fw-normal">
6570
Перевод отстаёт на {{ $docs->behind() }} изменения

resources/views/pages/status.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
<div class="container my-5">
2121
<div class="col-xl-10 col-md-12 mx-auto">
2222
<div class="p-5 mb-4 bg-body-secondary rounded-3 position-relative">
23-
<div class="row row-cols-md-4 g-3">
23+
<div class="row row-cols-md-4 g-3 justify-content-md-between text-center">
2424
@foreach (\App\Docs::SUPPORT_VERSIONS as $version)
25-
<div class="col">
25+
<div @class(['col', 'ms-auto' => !$loop->first])>
2626
<a href="{{ route('status', ['version' => $version]) }}"
2727
class="{{ $current === $version ? 'link-primary' : 'link-body-emphasis' }} text-decoration-none">
2828
Laravel {{ $version }}

0 commit comments

Comments
 (0)