becklyn/schema-org 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

becklyn/schema-org

最新稳定版本:1.7.0

Composer 安装命令:

composer require becklyn/schema-org

包简介

README 文档

README

This bundle provides a thin integration for rendering Schema.org-compatible JSON-LD meta data tags.

Creating a schema

Before you can render the meta data inside your templates, you need to implement a SchemaBuilderInterface for each entity type, that you want to generate a JSON-LD schema for.

An example SchemaBuilderInterface implementation would look like this, which would convert an MyNewsArticle into a Schema.org Article.

use App\Entity\MyNewsArticle;
use Becklyn\SchemaOrg\Data\Article;
use Becklyn\SchemaOrg\Data\Organization;
use Becklyn\SchemaOrg\Data\SchemaOrgDataInterface;
use Becklyn\SchemaOrg\SchemaBuilder\SchemaBuilderInterface;

class MyNewsSchemaBuilder implements SchemaBuilderInterface
{
    /**
     * @inheritDoc
     */
    public function supports ($entity, ?string $usage = null, array $context = []) : bool
    {
        return $entity instanceof MyNewsArticle;
    }


    /**
     * @inheritDoc
     */
    public function buildSchema ($entity, ?string $usage = null, array $context = []) : ?SchemaOrgDataInterface
    {
        \assert($entity instanceof MyNewsArticle);

        // Don't generate metadata for unpublished news
        if (!$entity->isPublished())
        {
            return null;
        }

        return (new Article())
            ->withEditor($entity->getAuthor())
            ->withAbout($entity->getTeaserText())
            ->withArticleBody($entity->getTextContent())
            ->withPublisher(
                (new Organization())
                    ->withName("Awesome Publisher")
                    ->withEmail("news@example.com")
            )
            ->withLicense("Creative Commons Attribution-ShareAlike 3.0")
        ;
    }
}

Render meta data tag

To render the JSON-LD meta data tag, call the Twig function {{ schema_org_meta_data(myAppEntity) }} and pass in an optional usage and context parameter, if you need to tweak the output based on the current render context.

统计信息

  • 总下载量: 7.59k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-08-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固