milankyncl / nette-seo
Nette SEO 模块,用于构建SEO优化的网站。
v1.1.2
2020-02-01 23:53 UTC
This package is not auto-updated.
Last update: 2024-09-23 07:59:12 UTC
README
Nette框架SEO扩展是一个简单的模块,用于简单步骤中构建网站的head meta标签。
安装
composer require milankyncl/nette-seo
使用
-
在您的
config.neon
文件中注册扩展。extensions: # ... seo: MilanKyncl\Nette\SEO\DI\SEOExtension
-
设置您的偏好。
seo: site_name: "Super cool website!" # Your website Name description: "Description for your website" # Website default description image: url: "//www.example.cz/super-cool-image.png" # Preview image URL width: 1260 # Image width height: 630 # Image height # Or just: # image: "//www.example.cz/super-cool-image.png" separator: '-' # Title separator customTags: # Your custom tags, will show before title tag copyright: 'Company 2018' # Copyright eg. author: 'Name <email@email.com>' # Author eg.
-
在您的 BasePresenter 中注入 SEOResolver 工厂和 MetaTags 组件。
// With @inject annotation: /** @var \MilanKyncl\Nette\SEO\SEOResolver @inject */ public $seo; /** @var \MilanKyncl\Nette\SEO\Components\MetaTags @inject */ public $metaTagsComponent; // Or in constructor: public function __construct(\MilanKyncl\Nette\SEO\SEOResolver $seo, \MilanKyncl\Nette\SEO\Components\MetaTags $metaTagsComponent) { $this->seo = $seo; $this->metaTagsComponent = $metaTagsComponent; }
-
创建 SEO Meta 标签组件(在 BasePresenter 中),并在您的操作中设置标题、描述或自定义元标签。使用 文档 中的方法。
// HomepagePresenter eg. public function indexAction() { $this->seo->setTitle('Homepage'); // The title will look like: Homepage - Super cool website! ({$title} {$separator} {$site_name}) } // Base Presenter public function createComponentSeoMetaTags() { // You can use some methods to change default options from documentation here // before returning the component // $this->seo–>setTitle($title) // $this->seo–>setDescription($description) // $this->seo–>setImage($url, $width, $height) // Use this right before returning the component $this->metaTagsComponent->setResolver($this->seo); return $this->metaTagsComponent; }
-
在您的 .latte 文件中放置控制宏。
<html> <head> {* * Will genereate all custom meta tags, * then title and finally seo tags *} {control seoMetaTags} {* Your head content *} <link rel="stylesheet" href="style.css"> </head> <body> </body> </html>
文档
配置
site_name
您站点的名称,将在 <title>
标签中显示在页面标题之前/之后和分隔符。将设置 og:title
、twitter:title
、og:site_name
元属性。
default: null
options: string
description
您页面的描述,将在 description
、og:description
、twitter:description
元属性中设置。
default: null
options: string
type
您对象/内容的类型。有关该属性的更多信息,请参阅 ogp.me#types。
default: 'website'
options: string
image
您网站的预览图片。将设置 og:image
、twitter:image
。您只能指定图片的URL,或者指定 url
、width
和 height
参数。
default: null
options: string|object
separator
您 <title>
元素中的分隔符。
default: '-'
options: string
customTags
自定义元标签。数组项的键将出现 name
属性,其值将出现在 content
属性中。
default: []
options: Array