承接 ajur-media/json-ld-generator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ajur-media/json-ld-generator

Composer 安装命令:

composer require ajur-media/json-ld-generator

包简介

Extremely simple JSON-LD markup generator (AJUR Media fork)

README 文档

README

Extremely simple JSON-LD generator.

AJUR Media fork, compatible with PHP7.4 & PHP 8.*

Original code:

Installation

From the command line run

$ composer require ajur-media/json-ld-generator

Methods

/Context.php

  • create($context, array $data = [])
  • getProperties()
  • generate($flags)

Context Types

  • article
  • audiobook
  • beach
  • blog_posting
  • book
  • breadcrumb_list
  • contact_point
  • corporation
  • creative_work
  • duration
  • event
  • geo_coordinates
  • image_object
  • invoice
  • list_item
  • local_business
  • media_object
  • music_album
  • music_group
  • music_playlist
  • music_recording
  • news_article
  • offer
  • order
  • organization
  • person
  • place
  • postal_address
  • price_specification
  • product
  • rating
  • recipe
  • review
  • sculpture
  • search_box
  • thing
  • video_object
  • web_page
  • web_site

Examples

Quick Example

Business

$context = \AJUR\Toolkit\JsonLd\Context::create('local_business', [
    'name' => 'Consectetur Adipiscing',
    'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor',
    'telephone' => '555-555-5555',
    'openingHours' => 'mon,tue,fri',
    'address' => [
        'streetAddress' => '112 Apple St.',
        'addressLocality' => 'Hamden',
        'addressRegion' => 'CT',
        'postalCode' => '06514',
    ],
    'geo' => [
        'latitude' => '41.3958333',
        'longitude' => '-72.8972222',
    ],
]);

echo $context; // Will output the script tag

News Article

$context = \JsonLd\Context::create('news_article', [
    'headline' => 'Article headline',
    'description' => 'A most wonderful article',
    'mainEntityOfPage' => [
        'url' => 'https://google.com/article',
    ],
    'image' => [
        'url' => 'https://google.com/thumbnail1.jpg',
        'height' => 800,
        'width' => 800,
    ],
    'datePublished' => '2015-02-05T08:00:00+08:00',
    'dateModified' => '2015-02-05T09:20:00+08:00',
    'author' => [
        'name' => 'John Doe',
    ],
    'publisher' => [
        'name' => 'Google',
        'logo' => [
          'url' => 'https://google.com/logo.jpg',
          'width' => 600,
          'height' => 60,
        ]
    ],
]);

echo $context; // Will output the script tag

Custom Context Type

The first argument for the create($context, array $data = []) method also accepts class names. This is helpful for custom context types.

<?php

namespace App\JsonLd;

use JsonLd\ContextTypes\AbstractContext;

class FooBar extends AbstractContext
{
    /**
     * Property structure
     *
     * @var array
     */
    protected $structure = [
        'name' => null,
        'description' => null,
        'image' => null,
        'url' => null,
    ];
}
$context = \JsonLd\Context::create(\App\JsonLd\FooBar::class, [
    'name' => 'Foo Foo headline',
    'description' => 'Bar bar article description',
    'url' => 'http://google.com',
]);

echo $context; // Will output the script tag

Breadcrumbs

Breadcrumb trails on a page indicate the page's position in the site hierarchy. A user can navigate all the way up in the site hierarchy, one level at a time, by starting from the last breadcrumb in the breadcrumb trail.

Example

$context = \JsonLd\Context::create('breadcrumb_list', [
    'itemListElement' => [
        [
            'url' => 'https://example.com/arts',
            'name' => 'Arts',
        ],
        [
            'url' => 'https://example.com/arts/books',
            'name' => 'Books',
        ],
        [
            'url' => 'https://example.com/arts/books/poetry',
            'name' => 'Poetry',
        ],
    ]
]);

Output

<script type="application/ld+json">
{
  "@context": "http:\/\/schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {
      "@type": "ListItem",
      "position": 1,
      "item": {
        "@id": "https:\/\/example.com\/arts",
        "name": "Arts"
      }
    },
    {
      "@type": "ListItem",
      "position": 2,
      "item": {
        "@id": "https:\/\/example.com\/arts\/books",
        "name": "Books"
      }
    },
    {
      "@type": "ListItem",
      "position": 3,
      "item": {
        "@id": "https:\/\/example.com\/arts\/books\/poetry",
        "name": "Poetry"
      }
    }
  ]
}
</script>

Search Box

With Google Sitelinks search box, from search results. Search users sometimes use navigational queries, typing in the brand name or URL of a known site or app, only to do a more detailed search once they reach their destination. For example, users searching for pizza pins on Pinterest would type Pinterest or pinterest.com into Google Search--either from the Google App or from their web browser--then load the site or Android app, and finally search for pizza.

Example

$context = \JsonLd\Context::create('search_box', [
    'url' => 'https://www.example.com/',
    'potentialAction' => [
        'target' => 'https://query.example.com/search?q={search_term_string}',
        'query-input' => 'required name=search_term_string',
    ],
]);

Output

<script type="application/ld+json">
{
  "@context": "http:\/\/schema.org",
  "@type": "WebSite",
  "url": "https:\/\/www.example.com\/",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "https:\/\/query.example.com\/search?q={search_term_string}",
    "query-input": "required name=search_term_string"
  }
}
</script>

ajur-media/json-ld-generator 适用场景与选型建议

ajur-media/json-ld-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 116 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「generator」 「schema」 「JSON-LD」 「structured-data」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ajur-media/json-ld-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ajur-media/json-ld-generator 我们能提供哪些服务?
定制开发 / 二次开发

基于 ajur-media/json-ld-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-2-Clause
  • 更新时间: 2024-06-28