diff --git a/js/src/forum/addTagFilter.js b/js/src/forum/addTagFilter.js index 39316186..95ed7c78 100644 --- a/js/src/forum/addTagFilter.js +++ b/js/src/forum/addTagFilter.js @@ -23,8 +23,14 @@ export default function() { extend(IndexPage.prototype, 'view', function(vdom) { const tag = this.currentTag(); + if (tag) vdom.attrs.className += ' IndexPage--tag'+tag.id(); + }); + + extend(IndexPage.prototype, 'config', function() { + const tag = this.currentTag(); + if (tag) { - vdom.attrs.className += ' IndexPage--tag'+tag.id(); + app.setTitle(tag.name()); } }); diff --git a/js/src/forum/components/TagsPage.js b/js/src/forum/components/TagsPage.js index 952e089a..8ff703f0 100644 --- a/js/src/forum/components/TagsPage.js +++ b/js/src/forum/components/TagsPage.js @@ -84,4 +84,11 @@ export default class TagsPage extends Page { ); } + + config(...args) { + super.config(...args); + + app.setTitle(app.translator.trans('flarum-tags.forum.meta.tags_title')); + app.setTitleCount(0); + } } diff --git a/src/Content/Tag.php b/src/Content/Tag.php index a6633198..183fd2e7 100644 --- a/src/Content/Tag.php +++ b/src/Content/Tag.php @@ -14,6 +14,7 @@ use Flarum\Frontend\Document; use Flarum\Tags\TagRepository; use Flarum\User\User; +use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\View\Factory; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface as Request; @@ -35,15 +36,23 @@ class Tag */ protected $tags; + /** + * @var Translator + */ + protected $translator; + /** * @param Client $api * @param Factory $view + * @param TagRepository $tags + * @param Translator $translator */ - public function __construct(Client $api, Factory $view, TagRepository $tags) + public function __construct(Client $api, Factory $view, TagRepository $tags, Translator $translator) { $this->api = $api; $this->view = $view; $this->tags = $tags; + $this->translator = $translator; } public function __invoke(Document $document, Request $request) @@ -71,6 +80,12 @@ public function __invoke(Document $document, Request $request) $apiDocument = $this->getApiDocument($actor, $params); + $document->title = $tag->name; + if ($tag->description) { + $document->meta['description'] = $tag->description; + } else { + $document->meta['description'] = $this->translator->trans('flarum-tags.forum.meta.tag_description', ['{tag}' => $tag->name]); + } $document->content = $this->view->make('tags::frontend.content.tag', compact('apiDocument', 'page', 'tag')); $document->payload['apiDocument'] = $apiDocument; diff --git a/src/Content/Tags.php b/src/Content/Tags.php index 517cd123..8c3a93bb 100644 --- a/src/Content/Tags.php +++ b/src/Content/Tags.php @@ -14,6 +14,7 @@ use Flarum\Http\UrlGenerator; use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Tags\TagRepository; +use Illuminate\Contracts\Translation\Translator; use Illuminate\Contracts\View\Factory; use Illuminate\Support\Arr; use Psr\Http\Message\ServerRequestInterface as Request; @@ -35,6 +36,11 @@ class Tags */ protected $tags; + /** + * @var Translator + */ + protected $translator; + /** * @var SettingsRepositoryInterface */ @@ -49,15 +55,23 @@ class Tags * @param Client $api * @param Factory $view * @param TagRepository $tags + * @param Translator $translator * @param SettingsRepositoryInterface $settings * @param UrlGenerator $url */ - public function __construct(Client $api, Factory $view, TagRepository $tags, SettingsRepositoryInterface $settings, UrlGenerator $url) - { + public function __construct( + Client $api, + Factory $view, + TagRepository $tags, + Translator $translator, + SettingsRepositoryInterface $settings, + UrlGenerator $url + ) { $this->api = $api; $this->view = $view; $this->tags = $tags; $this->settings = $settings; + $this->translator = $translator; $this->url = $url; } @@ -77,6 +91,8 @@ public function __invoke(Document $document, Request $request) ]; }); + $document->title = $this->translator->trans('flarum-tags.forum.meta.tags_title'); + $document->meta['description'] = $this->translator->trans('flarum-tags.forum.meta.tags_description'); $document->content = $this->view->make('tags::frontend.content.tags', compact('primaryTags', 'secondaryTags', 'children')); $document->canonicalUrl = $defaultRoute === '/tags' ? $this->url->to('forum')->base() : $request->getUri()->withQuery('');