Skip to content

Commit

Permalink
Merge pull request #1622 from Kolalexx/main
Browse files Browse the repository at this point in the history
fixed title for page show Chapter, Exercise, Solution
  • Loading branch information
fey authored Apr 4, 2024
2 parents 3f6ea0c + c435b5b commit fd0ed51
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 8 deletions.
14 changes: 14 additions & 0 deletions app/Models/Chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

namespace App\Models;

use App\Presenters\ChapterPresenter;
use Hemp\Presenter\Presentable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;

/**
* @method ChapterPresenter present()
*/
class Chapter extends Model
{
use Presentable;

public string $defaultPresenter = ChapterPresenter::class;

public const MARKABLE_COUNT = 101;

public function members(): HasMany
Expand Down Expand Up @@ -46,4 +55,9 @@ public function getChapterLevel(): int
{
return count(explode('.', $this->path));
}

public function getFullTitle(): string
{
return $this->present()->fullTitle;
}
}
22 changes: 22 additions & 0 deletions app/Presenters/ChapterPresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Presenters;

use App\Models\Chapter;
use Hemp\Presenter\Presenter;

/**
* @mixin Chapter
* @property-read string $fullTitle
*/
class ChapterPresenter extends Presenter
{
public function getFullTitleAttribute(): string
{
$path = $this->path;

$chapterTitle = __("sicp.chapters")[$path];

return "$path $chapterTitle";
}
}
2 changes: 1 addition & 1 deletion resources/lang/en/chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'finish' => 'Finish the chapter',
'confirm_finish' => 'Are you sure you want to complete the chapter?',
],
'chapter' => 'Chapter',
'chapter' => 'Chapter :chapter',
'index' => [
'description' => 'Contents of the book Structure and Interpretation of Computer Programs',
],
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/exercise.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'exercise' => 'Exercise',
'exercise' => 'Exercise :exercise',
'index' => [
'description' => 'List of exercises in the book Structure and Interpretation of Computer Programs',
],
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en/solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
'exercise' => 'Exercise',
'code_review' => 'Code Review',
'sub_title' => 'Compare your solutions',
'solution_for_title' => 'Solution for Exercise :exercise',
];
2 changes: 1 addition & 1 deletion resources/lang/ru/chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'finish' => 'Завершить главу',
'confirm_finish' => 'Вы уверены, что хотите завершить главу?',
],
'chapter' => 'Глава',
'chapter' => 'Глава :chapter',
'index' => [
'description' => 'Оглавление книги Структура и интерпретация компьютерных программ',
],
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ru/exercise.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

return [
'exercise' => 'Упражнение',
'exercise' => 'Упражнение :exercise',
'index' => [
'description' => 'Cписок упражнений книги Структура и интерпретация компьютерных программ',
],
Expand Down
1 change: 1 addition & 0 deletions resources/lang/ru/solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
'exercise' => 'Упражнение',
'code_review' => 'Код Ревью',
'sub_title' => 'Сравни свои решения',
'solution_for_title' => 'Решение для упражнения :exercise',
];
4 changes: 2 additions & 2 deletions resources/views/chapter/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
@endphp
@section('title')
{{ getTitleContent(App\Helpers\ChapterHelper::fullChapterName($chapter->path)) }}
{{ getTitleContent(__('chapter.chapter', ['chapter' => $chapter->getFullTitle()])) }}
@endsection
@section('description')
@foreach (Breadcrumbs::generate('chapter', $chapter) as $breadcrumb)
Expand Down Expand Up @@ -38,7 +38,7 @@ class="sticky-top col-md-12 d-flex {{ $previousChapter->exists ? 'justify-conten
@endif
</small>
<h1 class="h2">
{{ App\Helpers\ChapterHelper::fullChapterName($chapter->path) }}
{{ $chapter->getFullTitle() }}
<small>
<a class="text-muted" target="_blank" href="{{ getChapterOriginLink($chapter) }}" data-bs-toggle="tooltip"
data-bs-placement="right" title="{{ __('layout.common.origin') }}">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/exercise/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
@endphp
@section('title')
{{ getTitleContent($exercise->getTitle()) }}
{{ getTitleContent(__('exercise.exercise', ['exercise' => $exercise->getFullTitle()])) }}
@endsection
@section('description')
{{ __('exercise.exercise') }} {{ $exercise->path }} {{ $exercise->getTitle() }} {{ __('exercise.show.description') }}
Expand Down
4 changes: 3 additions & 1 deletion resources/views/solution/show.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@extends('layouts.app')

@section('meta-robots', 'nofollow, noindex')
@section('title'){{ __('solution.exercise') }} {{ getTitleContent($currentExercise->getFullTitle()) }}@endsection
@section('title')
{{ getTitleContent(__('solution.solution_for_title', ['exercise' => $currentExercise->getFullTitle()])) }}
@endsection
@section('description'){{ $user->id }} - {{ __('solution.code_review') }} - {{ $user->name }} -
{{ __('solution.exercise') }} {{ $currentExercise->getFullTitle() }}@endsection

Expand Down

0 comments on commit fd0ed51

Please sign in to comment.