mirror of
https://github.com/flarum/core.git
synced 2025-08-15 12:54:47 +02:00
Add title and description meta tags (#72)
This commit is contained in:
committed by
GitHub
parent
c2f8aeeecc
commit
6117c1231a
@@ -23,8 +23,14 @@ export default function() {
|
|||||||
extend(IndexPage.prototype, 'view', function(vdom) {
|
extend(IndexPage.prototype, 'view', function(vdom) {
|
||||||
const tag = this.currentTag();
|
const tag = this.currentTag();
|
||||||
|
|
||||||
|
if (tag) vdom.attrs.className += ' IndexPage--tag'+tag.id();
|
||||||
|
});
|
||||||
|
|
||||||
|
extend(IndexPage.prototype, 'config', function() {
|
||||||
|
const tag = this.currentTag();
|
||||||
|
|
||||||
if (tag) {
|
if (tag) {
|
||||||
vdom.attrs.className += ' IndexPage--tag'+tag.id();
|
app.setTitle(tag.name());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -84,4 +84,11 @@ export default class TagsPage extends Page {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config(...args) {
|
||||||
|
super.config(...args);
|
||||||
|
|
||||||
|
app.setTitle(app.translator.trans('flarum-tags.forum.meta.tags_title'));
|
||||||
|
app.setTitleCount(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,7 @@ use Flarum\Api\Controller\ListDiscussionsController;
|
|||||||
use Flarum\Frontend\Document;
|
use Flarum\Frontend\Document;
|
||||||
use Flarum\Tags\TagRepository;
|
use Flarum\Tags\TagRepository;
|
||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
|
use Illuminate\Contracts\Translation\Translator;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
@@ -35,15 +36,23 @@ class Tag
|
|||||||
*/
|
*/
|
||||||
protected $tags;
|
protected $tags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Translator
|
||||||
|
*/
|
||||||
|
protected $translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $api
|
* @param Client $api
|
||||||
* @param Factory $view
|
* @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->api = $api;
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
$this->tags = $tags;
|
$this->tags = $tags;
|
||||||
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __invoke(Document $document, Request $request)
|
public function __invoke(Document $document, Request $request)
|
||||||
@@ -71,6 +80,12 @@ class Tag
|
|||||||
|
|
||||||
$apiDocument = $this->getApiDocument($actor, $params);
|
$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->content = $this->view->make('tags::frontend.content.tag', compact('apiDocument', 'page', 'tag'));
|
||||||
$document->payload['apiDocument'] = $apiDocument;
|
$document->payload['apiDocument'] = $apiDocument;
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@ use Flarum\Frontend\Document;
|
|||||||
use Flarum\Http\UrlGenerator;
|
use Flarum\Http\UrlGenerator;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
use Flarum\Tags\TagRepository;
|
use Flarum\Tags\TagRepository;
|
||||||
|
use Illuminate\Contracts\Translation\Translator;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
@@ -35,6 +36,11 @@ class Tags
|
|||||||
*/
|
*/
|
||||||
protected $tags;
|
protected $tags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Translator
|
||||||
|
*/
|
||||||
|
protected $translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var SettingsRepositoryInterface
|
* @var SettingsRepositoryInterface
|
||||||
*/
|
*/
|
||||||
@@ -49,15 +55,23 @@ class Tags
|
|||||||
* @param Client $api
|
* @param Client $api
|
||||||
* @param Factory $view
|
* @param Factory $view
|
||||||
* @param TagRepository $tags
|
* @param TagRepository $tags
|
||||||
|
* @param Translator $translator
|
||||||
* @param SettingsRepositoryInterface $settings
|
* @param SettingsRepositoryInterface $settings
|
||||||
* @param UrlGenerator $url
|
* @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->api = $api;
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
$this->tags = $tags;
|
$this->tags = $tags;
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
|
$this->translator = $translator;
|
||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +91,8 @@ class Tags
|
|||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$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->content = $this->view->make('tags::frontend.content.tags', compact('primaryTags', 'secondaryTags', 'children'));
|
||||||
$document->canonicalUrl = $defaultRoute === '/tags' ? $this->url->to('forum')->base() : $request->getUri()->withQuery('');
|
$document->canonicalUrl = $defaultRoute === '/tags' ? $this->url->to('forum')->base() : $request->getUri()->withQuery('');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user