项目作者: Magiczne

项目描述 :
October CMS JSON-LD components for schema.org with nesting support.
高级语言: PHP
项目地址: git://github.com/Magiczne/october-json-ld.git
创建时间: 2020-07-30T07:12:54Z
项目社区:https://github.com/Magiczne/october-json-ld

开源协议:MIT License

下载


october-json-ld

October CMS JSON-LD components for schema.org with nesting support.

Based on schema.org version 9.0 WITHOUT pending
schemas and properties.

Information

This plugin adds component for many of the https://schema.org schemas.

List of currently supported schemas and enumerations

Usage

Basic usage example

  1. Add component to your layout or page and configure it
    Component configuration

  2. Render it using the component syntax

    1. {% component 'Thing' %}
  3. Component should render this code:
    1. <script type="application/ld+json">
    2. {
    3. "@context": "https://schema.org",
    4. "@type": "Thing",
    5. "description": "Example description",
    6. "name": "Example name"
    7. }
    8. </script>

Advanced usage

IMPORTANT 1: Currently there are no checks performed to ensure that circular dependencies are not happening.
Have that in mind when referencing one component in another.

IMPORTANT 2: Currently there is no support for referencing multiple components in one field, but it is planned
to do.

IMPORTANT 3: When you reference component which does not exist in the page or layout exception will be thrown.

IMPORTANT 4: When you reference component which is not a valid JSON-LD component exception will be thrown.

This plugin supports referencing components inside other components if there are added to the same page or
to the currently used layout.

To do to you need to use following syntax:

  1. To reference component added to the same page use page:componentAlias
  2. To reference component added to the currently used layout use layout:componentAlias

Example:

  1. Insert Thing and ImageObject component to the page and configure them
ImageObject Thing
Thing component configuration ImageObject component configuration
  1. Insert code into your template:

    1. {% component 'Thing' %}
  2. Component should render this code:

    1. <script type="application/ld+json">
    2. {
    3. "@context": "https://schema.org",
    4. "@type": "Thing",
    5. "description": "Example description",
    6. "image": {
    7. "@type": "ImageObject",
    8. "caption": "Image caption"
    9. },
    10. "name": "Example name"
    11. }
    12. </script>

Setting multiple values for property

If you want to have multiple values for one of the properties just separate values using semicolon.
Referencing multiple components with this syntax is also supported.

Example 1

Writing 250ml of milk; 2 eggs; banana in one of the component parameters will results in the
array of data being rendered into JSON like so

  1. <script type="application/ld+json">
  2. {
  3. "@context": "https://schema.org",
  4. "@type": "Recipe",
  5. "recipeIngredient": [
  6. "250ml of milk",
  7. "egg",
  8. "banana"
  9. ]
  10. }
  11. </script>

Example 2

Writing page:componentAlias1; layout:componentAlias2 in one of the component parameters will result
in the array of data being rendered into JSON like so

  1. <script type="application/ld+json">
  2. {
  3. "@context": "https://schema.org",
  4. "@type": "Menu",
  5. "hasMenuItem": [
  6. {
  7. "@type": "MenuItem",
  8. "name": "First menu item"
  9. },
  10. {
  11. "@type": "MenuItem",
  12. "name": "Second menu item"
  13. }
  14. ]
  15. }
  16. </script>