vrestihnat / meta-canonical-control
Nette control for managing meta data and canonical link in HTML header.
1.4.2
2021-01-26 14:04 UTC
Requires
- php: >=7.4.0
- nette/application: ^3.0@dev
Requires (Dev)
- php-coveralls/php-coveralls: ^2.4
- phpstan/phpstan: ^0.12.69
- phpstan/phpstan-nette: ^0.12.14
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: ^9.5
- spaze/phpstan-disallowed-calls: ^1.1
README
Installation
Via Composer:
$ composer require vrestihnat/meta-canonical-control
Usage
First register the control factory in your config and optionally set up default metadata:
services: - implement: Vrestihnat\MetaControl\IMetaControlFactory setup: - setCharset('utf-8') - setAuthor('Jon Doe')
Use the control factory in your presenter:
protected function createComponentMeta(): Vrestihnat\MetaControl\MetaControl { $control = $this->metaControlFactory->create(); $control->setDescription('Lorem ipsum'); return $control; }
And render it in your Latte template:
<html> <head> {control meta} </head> <body> ... </body> </html>
Overview of supported meta tags
Charset:
// <meta charset="utf-8"> $control->setCharset('utf-8'); $control->getCharset(); // 'utf-8'
Document metadata:
// <meta name="author" content="John Doe"> $control->setMetadata('author', 'Jon Doe'); $control->getMetadata('author'); // 'Jon Doe'
Document properties:
// <meta property="og:title" content="Foo title"> $control->setProperty('og:title', 'Foo title'); $control->getProperty('og:title'); // 'Foo title'
Pragma directives:
// <meta http-equiv="content-type" content="text/html; charset=UTF-8"> $control->setPragma('content-type', 'text/html; charset=UTF-8'); $control->getPragma('content-type'); // 'text/html; charset=UTF-8'
Shorthands for standard metadata
Author:
// <meta name="author" content="John Doe"> $control->setAuthor('Jon Doe'); $control->getAuthor(); // 'Jon Doe'
Description:
// <meta name="description" content="Lorem ipsum"> $control->setDescription('Lorem ipsum'); $control->getDescription(); // 'Lorem ipsum'
Keywords:
// <meta name="keywords" content="foo, bar, baz"> $control->setKeywords('foo', 'bar'); $control->addKeyword('baz'); $control->getKeywords(); // ['foo', 'bar', 'baz']
Robots:
// <meta name="robots" content="noindex, nofollow"> $control->setRobots('noindex, nofollow'); $control->getRobots(); // 'noindex, nofollow'
New features
Canonical link:
// <link rel="canonical" href="/test/3"> $control->setCanonical('/test/3');
Prev (paging):
// <link rel="prev" href="test/3/page/1"> $control->setPrev('/test/3/page/1');
Next (paging):
// <link rel="next" href="/test/3/page/3"> $control->setNext('/test/3/page/3');
Set not unique meta e.g. google-site-verification
// <meta name="google-site-verification" content="123456789abcdefghijklmnopqrstuvwxyzABCDEFGH">\n<meta name="google-site-verification" content="HGFEDCBAzyxwvutsrqponmlkjihgfedcba987654321">\n $control->setMetadata('google-site-verification', '123456789abcdefghijklmnopqrstuvwxyzABCDEFGH'); $control->setMetadata('google-site-verification', 'HGFEDCBAzyxwvutsrqponmlkjihgfedcba987654321');