All Projects → Torann → Json Ld

Torann / Json Ld

Licence: bsd-2-clause
Extremely simple JSON-LD generator.

Projects that are alternatives of or similar to Json Ld

Structured Data Json Ld
Collection of structured data snippets in Google preferred JSON-LD format.
Stars: ✭ 157 (+26.61%)
Mutual labels:  json-ld, article
Hypergraphql
GraphQL interface for querying and serving linked data on the Web.
Stars: ✭ 112 (-9.68%)
Mutual labels:  json-ld
Kanban Board
A sample application demonstrating a basic kanban board, seeded with vue-cli
Stars: ✭ 76 (-38.71%)
Mutual labels:  article
Kglab
Graph-Based Data Science: an abstraction layer in Python for building knowledge graphs, integrated with popular graph libraries – atop Pandas, RDFlib, pySHACL, RAPIDS, NetworkX, iGraph, PyVis, pslpython, pyarrow, etc.
Stars: ✭ 98 (-20.97%)
Mutual labels:  json-ld
Avdetection
A simple way for detection the remote user's antivirus
Stars: ✭ 82 (-33.87%)
Mutual labels:  article
Codebook
Cook rmarkdown codebooks from metadata on R data frames
Stars: ✭ 105 (-15.32%)
Mutual labels:  json-ld
Node Blog
🔥✨ A react blog project base on nodejs, nestjs, mongoose, typescript, react, ant-design,nextjs
Stars: ✭ 69 (-44.35%)
Mutual labels:  article
React Structured Data
React Structured Data provides an easy way to add structured data to your React apps
Stars: ✭ 120 (-3.23%)
Mutual labels:  json-ld
Post Feature Visualization
Feature Visualization
Stars: ✭ 106 (-14.52%)
Mutual labels:  article
Rdf Ext
RDF library for NodeJS and the Browsers
Stars: ✭ 97 (-21.77%)
Mutual labels:  json-ld
Getnews.tech
A web server that fetches data from the News API and formats it for display in the terminal.
Stars: ✭ 94 (-24.19%)
Mutual labels:  article
Jsonld.js
A JSON-LD Processor and API implementation in JavaScript
Stars: ✭ 1,212 (+877.42%)
Mutual labels:  json-ld
Rdflib
RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
Stars: ✭ 1,584 (+1177.42%)
Mutual labels:  json-ld
Jekyll Seo Tag
A Jekyll plugin to add metadata tags for search engines and social networks to better index and display your site's content.
Stars: ✭ 1,226 (+888.71%)
Mutual labels:  json-ld
Web Annotation
Web Annotation Working Group repository, see README for links to specs
Stars: ✭ 112 (-9.68%)
Mutual labels:  json-ld
Trustgraph
Decentralized trust ratings using signed claims
Stars: ✭ 75 (-39.52%)
Mutual labels:  json-ld
Good Articles By Sort
本仓库用来存放我看过的认为比较好的文章---根据分类排序
Stars: ✭ 93 (-25%)
Mutual labels:  article
Ios Learning Materials
📚Curated list of articles, web-resources, tutorials and code repositories that may help you dig a little bit deeper into iOS [and Apple Platforms].
Stars: ✭ 1,380 (+1012.9%)
Mutual labels:  article
Json Gold
A JSON-LD processor for Go
Stars: ✭ 122 (-1.61%)
Mutual labels:  json-ld
Hypergraphql
GraphQL interface for querying and serving linked data on the Web.
Stars: ✭ 120 (-3.23%)
Mutual labels:  json-ld

JSON-LD Generator

Build Status Latest Stable Version Total Downloads Patreon donate button Donate weekly to this project using Gratipay Donate to this project using Flattr Donate to this project using Paypal

Extremely simple JSON-LD generator.

Installation

From the command line run

$ composer require torann/json-ld

Methods

/JsonLd/Context.php

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

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 = \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

Using the JSON-LD in a Laracasts Presenter

Even though this example shows using the JSON-LD inside of a Laracasts\Presenter presenter, Laravel is not required for this package.

/App/Presenters/BusinessPresenter.php

<?php

namespace App\Presenters;

use JsonLd\Context;
use Laracasts\Presenter\Presenter;

class BusinessPresenter extends Presenter
{
    /**
     * Create JSON-LD object.
     *
     * @return \JsonLd\Context
     */
    public function jsonLd()
    {
        return Context::create('local_business', [
            'name' => $this->entity->name,
            'description' => $this->entity->description,
            'telephone' => $this->entity->telephone,
            'openingHours' => 'mon,tue,fri',
            'address' => [
                'streetAddress' => $this->entity->address,
                'addressLocality' => $this->entity->city,
                'addressRegion' => $this->entity->state,
                'postalCode' => $this->entity->postalCode,
            ],
            'geo' => [
                'latitude' => $this->entity->location->lat,
                'longitude' => $this->entity->location->lng,
            ],
        ]);
    }
}

Generate the Tags

The generator comes with a __toString method that will automatically generate the correct script tags when displayed as a string.

Inside of a Laravel View

echo $business->present()->jsonLd();

Inside of a Laravel View

{!! $business->present()->jsonLd() !!}

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].