Skip to content

Commit

Permalink
Changed docs behind
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Nov 12, 2023
1 parent bc21455 commit 7ac8af1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 28 deletions.
4 changes: 1 addition & 3 deletions app/Console/Commands/CompareDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use App\Docs;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;

class CompareDocument extends Command
{
Expand All @@ -28,7 +26,7 @@ class CompareDocument extends Command
*/
public function handle()
{
collect(Docs::SUPPORT_VERSIONS)->each(fn(string $version) => $this->updateVersion($version));
collect(Docs::SUPPORT_VERSIONS)->each(fn (string $version) => $this->updateVersion($version));
}

/**
Expand Down
34 changes: 17 additions & 17 deletions app/Docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Docs
public const SUPPORT_VERSIONS = [
'8.x',
'5.4',
'4.2'
'4.2',
];

/**
Expand Down Expand Up @@ -64,7 +64,7 @@ class Docs
*/
public function __construct(string $version, string $file)
{
$this->file = $file . '.md';
$this->file = $file.'.md';
$this->version = $version;
$this->path = "/$version/$this->file";

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

try {
$this->variables = Yaml::parse($variables);
}catch (\Throwable){
} catch (\Throwable) {

}
}
Expand All @@ -87,9 +87,9 @@ public function __construct(string $version, string $file)
*
* @param string $view The view name.
*
* @return \Illuminate\Contracts\View\View The rendered view of the documentation page.
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @return \Illuminate\Contracts\View\View The rendered view of the documentation page.
*/
public function view(string $view)
{
Expand All @@ -115,7 +115,7 @@ public function view(string $view)
*/
public function getMenu(): array
{
$page = Storage::disk('docs')->get($this->version . '/documentation.md');
$page = Storage::disk('docs')->get($this->version.'/documentation.md');

$html = Str::of($page)
->after('---')
Expand Down Expand Up @@ -156,7 +156,7 @@ public function docsToArray(string $html): array
$menu = [];

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

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

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

return $response->collect()
->takeUntil(fn($commit) => $commit['sha'] === $this->variables['git'])
->takeUntil(fn ($commit) => $commit['sha'] === $this->variables['git'])
->count();
}

Expand Down Expand Up @@ -237,11 +237,11 @@ public function goToOriginal(): string
*
* @return string
*/
static public function compareLink(string $version, string $hash): string
public static function compareLink(string $version, string $hash): string
{
$compactHash = Str::of($hash)->limit(7, '')->toString();

return "https://github.com/laravel/docs/compare/$version..$compactHash";
return "https://github.com/laravel/docs/compare/$compactHash..$version";
}

/**
Expand All @@ -262,9 +262,9 @@ public function getModel(): Document
}

/**
* @return int
* @return int|null
*/
public function behind():int
public function behind(): ?int
{
return $this->getModel()->behind;
}
Expand Down
7 changes: 4 additions & 3 deletions app/Http/Controllers/DocsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class DocsController extends Controller
* @param string $version
* @param string $page
*
* @return \Illuminate\View\View|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*
* @return \Illuminate\View\View|
*/
public function show(string $version = Docs::DEFAULT_VERSION, string $page = 'installation')
{
Expand All @@ -35,8 +36,8 @@ public function status(string $version = Docs::DEFAULT_VERSION)
->get();

return view('pages.status', [
'current' => $version,
'documents' => $documents
'current' => $version,
'documents' => $documents,
]);
}
}
2 changes: 1 addition & 1 deletion app/Models/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class Document extends Model
*/
protected $attributes = [
'version' => Docs::DEFAULT_VERSION,
'behind' => 0,
'behind' => null,
];
}
9 changes: 7 additions & 2 deletions resources/views/pages/docs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ class="{{ active(url($link['href']), 'active', 'link-body-emphasis') }} d-inline

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


@if ($docs->behind() > 0)
@if($docs->behind() === null)
<a href="{{ route('status', $docs->version) }}#{{ $docs->file }}" class="">
<span class="badge bg-primary-subtle text-primary rounded rounded-1 fs-6 fw-normal">
Перевод не имеет метки
</span>
</a>
@elseif ($docs->behind() > 0)
<a href="{{ route('status', $docs->version) }}#{{ $docs->file }}" class="">
<span class="badge bg-primary-subtle text-primary rounded rounded-1 fs-6 fw-normal">
Перевод отстаёт на {{ $docs->behind() }} изменения
Expand Down
4 changes: 2 additions & 2 deletions resources/views/pages/status.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<div class="container my-5">
<div class="col-xl-10 col-md-12 mx-auto">
<div class="p-5 mb-4 bg-body-secondary rounded-3 position-relative">
<div class="row row-cols-md-4 g-3">
<div class="row row-cols-md-4 g-3 justify-content-md-between text-center">
@foreach (\App\Docs::SUPPORT_VERSIONS as $version)
<div class="col">
<div @class(['col', 'ms-auto' => !$loop->first])>
<a href="{{ route('status', ['version' => $version]) }}"
class="{{ $current === $version ? 'link-primary' : 'link-body-emphasis' }} text-decoration-none">
Laravel {{ $version }}
Expand Down

0 comments on commit 7ac8af1

Please sign in to comment.