From fcf3d6640f5350db9c19b81ac56ec89989da0c9d Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Thu, 13 Feb 2020 00:20:34 -0500 Subject: [PATCH 1/6] Added title meta element based off of tags page(s) --- js/src/forum/addTagFilter.js | 18 +++++++++++++++--- js/src/forum/components/TagsPage.js | 6 ++++++ src/Content/Tag.php | 1 + src/Content/Tags.php | 18 ++++++++++++++++-- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/js/src/forum/addTagFilter.js b/js/src/forum/addTagFilter.js index 39316186..cae19d04 100644 --- a/js/src/forum/addTagFilter.js +++ b/js/src/forum/addTagFilter.js @@ -23,8 +23,16 @@ 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()); + } else { + app.setTitle(""); } }); @@ -44,8 +52,12 @@ export default function() { // Add a parameter for the IndexPage to pass on to the DiscussionList that // will let us filter discussions by tag. - extend(IndexPage.prototype, 'params', function(params) { - params.tags = m.route.param('tags'); + extend(IndexPage.prototype, 'params', function (params) { + if (m.route.param('tags')) { + params.tags = m.route.param('tags'); + } else { + params.tags = ""; + } }); // Translate that parameter into a gambit appended to the search query. diff --git a/js/src/forum/components/TagsPage.js b/js/src/forum/components/TagsPage.js index 952e089a..109428a4 100644 --- a/js/src/forum/components/TagsPage.js +++ b/js/src/forum/components/TagsPage.js @@ -84,4 +84,10 @@ export default class TagsPage extends Page { ); } + + config(...args) { + super.config(...args); + + app.setTitle(app.translator.trans('flarum-tags.forum.meta.tags_title')); + } } diff --git a/src/Content/Tag.php b/src/Content/Tag.php index a6633198..ebd580cd 100644 --- a/src/Content/Tag.php +++ b/src/Content/Tag.php @@ -71,6 +71,7 @@ public function __invoke(Document $document, Request $request) $apiDocument = $this->getApiDocument($actor, $params); + $document->title = $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..a022ff24 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 */ @@ -52,12 +58,19 @@ class Tags * @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 +90,7 @@ public function __invoke(Document $document, Request $request) ]; }); + $document->title = $this->translator->trans('flarum-tags.forum.meta.tags_title'); $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(''); From f1c65ae94cbd2184d00f97f62412565912ac5e90 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Thu, 13 Feb 2020 00:54:51 -0500 Subject: [PATCH 2/6] Added backend description meta support for SEO --- src/Content/Tag.php | 16 +++++++++++++++- src/Content/Tags.php | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Content/Tag.php b/src/Content/Tag.php index ebd580cd..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) @@ -72,6 +81,11 @@ 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 a022ff24..8c3a93bb 100644 --- a/src/Content/Tags.php +++ b/src/Content/Tags.php @@ -55,6 +55,7 @@ class Tags * @param Client $api * @param Factory $view * @param TagRepository $tags + * @param Translator $translator * @param SettingsRepositoryInterface $settings * @param UrlGenerator $url */ @@ -91,6 +92,7 @@ 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(''); From 7f1067479ccc5d0ab5b2e4581998eb2ba3f8495b Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Fri, 28 Feb 2020 20:02:47 -0500 Subject: [PATCH 3/6] Removed another unnecessary element --- js/src/forum/addTagFilter.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/js/src/forum/addTagFilter.js b/js/src/forum/addTagFilter.js index cae19d04..c712e036 100644 --- a/js/src/forum/addTagFilter.js +++ b/js/src/forum/addTagFilter.js @@ -53,11 +53,7 @@ export default function() { // Add a parameter for the IndexPage to pass on to the DiscussionList that // will let us filter discussions by tag. extend(IndexPage.prototype, 'params', function (params) { - if (m.route.param('tags')) { - params.tags = m.route.param('tags'); - } else { - params.tags = ""; - } + params.tags = m.route.param('tags'); }); // Translate that parameter into a gambit appended to the search query. From 488134e63b5b4b89bf16968bb5a4fa776b8d838b Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Fri, 28 Feb 2020 20:07:49 -0500 Subject: [PATCH 4/6] Removed unnecessary setTitle --- js/src/forum/addTagFilter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/js/src/forum/addTagFilter.js b/js/src/forum/addTagFilter.js index c712e036..568c74da 100644 --- a/js/src/forum/addTagFilter.js +++ b/js/src/forum/addTagFilter.js @@ -31,8 +31,6 @@ export default function() { if (tag) { app.setTitle(tag.name()); - } else { - app.setTitle(""); } }); From d7b340b611ca7feb2ffd9c8fe745f61d936e99ca Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Fri, 28 Feb 2020 20:08:59 -0500 Subject: [PATCH 5/6] Minor code style consistency change --- js/src/forum/addTagFilter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/src/forum/addTagFilter.js b/js/src/forum/addTagFilter.js index 568c74da..95ed7c78 100644 --- a/js/src/forum/addTagFilter.js +++ b/js/src/forum/addTagFilter.js @@ -26,7 +26,7 @@ export default function() { if (tag) vdom.attrs.className += ' IndexPage--tag'+tag.id(); }); - extend(IndexPage.prototype, 'config', function () { + extend(IndexPage.prototype, 'config', function() { const tag = this.currentTag(); if (tag) { @@ -50,7 +50,7 @@ export default function() { // Add a parameter for the IndexPage to pass on to the DiscussionList that // will let us filter discussions by tag. - extend(IndexPage.prototype, 'params', function (params) { + extend(IndexPage.prototype, 'params', function(params) { params.tags = m.route.param('tags'); }); From 747fa99ee10cad54a1cda418842ceedcb0c8e3ed Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Tue, 3 Mar 2020 15:46:29 -0500 Subject: [PATCH 6/6] Set title count on tags page to 0 --- js/src/forum/components/TagsPage.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/src/forum/components/TagsPage.js b/js/src/forum/components/TagsPage.js index 109428a4..8ff703f0 100644 --- a/js/src/forum/components/TagsPage.js +++ b/js/src/forum/components/TagsPage.js @@ -89,5 +89,6 @@ export default class TagsPage extends Page { super.config(...args); app.setTitle(app.translator.trans('flarum-tags.forum.meta.tags_title')); + app.setTitleCount(0); } }