项目作者: milankyncl

项目描述 :
Nette SEO component for building SEO optimized website.
高级语言: PHP
项目地址: git://github.com/milankyncl/nette-seo.git
创建时间: 2018-08-07T10:04:14Z
项目社区:https://github.com/milankyncl/nette-seo

开源协议:GNU General Public License v3.0

下载


Nette-framework SEO extension

Nette-framework SEO extension is a simple module to build head meta tags for website in simple steps.

Installation

  1. composer require milankyncl/nette-seo

Usage

  1. Register extension in your config.neon file.

    1. extensions:
    2. # ...
    3. seo: MilanKyncl\Nette\SEO\DI\SEOExtension
  2. Set your preferences.

    1. seo:
    2. site_name: "Super cool website!" # Your website Name
    3. description: "Description for your website" # Website default description
    4. image:
    5. url: "//www.example.cz/super-cool-image.png" # Preview image URL
    6. width: 1260 # Image width
    7. height: 630 # Image height
    8. # Or just:
    9. # image: "//www.example.cz/super-cool-image.png"
    10. separator: '-' # Title separator
    11. customTags: # Your custom tags, will show before title tag
    12. copyright: 'Company 2018' # Copyright eg.
    13. author: 'Name <email@email.com>' # Author eg.
  3. Inject SEOResolver factory and MetaTags component in your BasePresenter.

    1. // With @inject annotation:
    2. /** @var \MilanKyncl\Nette\SEO\SEOResolver @inject */
    3. public $seo;
    4. /** @var \MilanKyncl\Nette\SEO\Components\MetaTags @inject */
    5. public $metaTagsComponent;
    6. // Or in constructor:
    7. public function __construct(\MilanKyncl\Nette\SEO\SEOResolver $seo, \MilanKyncl\Nette\SEO\Components\MetaTags $metaTagsComponent) {
    8. $this->seo = $seo;
    9. $this->metaTagsComponent = $metaTagsComponent;
    10. }
  4. Create Seo Meta tags component (in BasePresenter) and in your action set title, description, or custom meta tags for your head. Use methods from documentation

    1. // HomepagePresenter eg.
    2. public function indexAction() {
    3. $this->seo->setTitle('Homepage'); // The title will look like: Homepage - Super cool website! ({$title} {$separator} {$site_name})
    4. }
    5. // Base Presenter
    6. public function createComponentSeoMetaTags() {
    7. // You can use some methods to change default options from documentation here
    8. // before returning the component
    9. // $this->seo–>setTitle($title)
    10. // $this->seo–>setDescription($description)
    11. // $this->seo–>setImage($url, $width, $height)
    12. // Use this right before returning the component
    13. $this->metaTagsComponent->setResolver($this->seo);
    14. return $this->metaTagsComponent;
    15. }
  5. Place control macro in your .latte file.

    1. <html>
    2. <head>
    3. {*
    4. * Will genereate all custom meta tags,
    5. * then title and finally seo tags
    6. *}
    7. {control seoMetaTags}
    8. {* Your head content *}
    9. <link rel="stylesheet" href="style.css">
    10. </head>
    11. <body>
    12. </body>
    13. </html>

Documentation

Configuration

site_name

Name of your site, will be showed in <title> tag after/before page title and separator. Will set og:title, twitter:title, og:site_name meta properies.

  1. default: null
  2. options: string

description

Description of your page, will set in description, og:description, twitter:description meta properties.

  1. default: null
  2. options: string

type

Type of your object/content. More info about the property at ogp.me#types.

  1. default: 'website'
  2. options: string

image

Preview image of your website. Will set og:image, twitter:image. You can specify only Url of image, or specify url, width and height parameters.

  1. default: null
  2. options: string|object

separator

Separator in your <title> element.

  1. default: '-'
  2. options: string

customTags

Custom meta tags. Key of array item will appear name attribute and its value will appear in content attribute.

  1. default: []
  2. options: Array