0.1.40 • Published 19 days ago

@tryghost/schema-org v0.1.40

Weekly downloads
2
License
MIT
Repository
github
Last release
19 days ago

Schema Org

Install

npm install @tryghost/schema-org --save

or

yarn add @tryghost/schema-org

Usage

const SchemaGenerator = require('@tryghost/schema-org');

const schema = new SchemaGenerator();
const makeSchemaTags = json => `<script type="application/ld+json">\n${json}\n</script>`;

// Schema data pertaining to the entire site
const site = {
    title: 'Ghost',
    url: 'https://demo.ghost.io',
    image: {
        url: 'https://static.ghost.org/v2.0.0/images/welcome-to-ghost.jpg',
        // Optional!
        dimensions: {
            width: 1600,
            height: 1050
        }
    }
};

// Example: generate schema for a post.
// Other supported options are `author`, `tag`, and `home`
const postObject = ghostPost(); // https://ghost.org/docs/api/v3/content/#posts

// Schema data pertaining to this specific resource
const postMeta = {
    author: {
        name: postObject.authors[0].name,
        url: postObject.authors[0].url,
        image: postObject.authors[0].profile_image,
        description: postObject.authors[0].meta_description || postObject.authors[0].bio
    },
    meta: {
        title: postObject.title,
        url: postObject.url,
        datePublished: postObject.published_at,
        dateModified: postObject.updated_at,
        image: postObject.feature_image,
        keywords: postObject.tags.map(({name}) => name),
        description: postObject.custom_excerpt || postObject.excerpt
    }
};

// Logs a valid JSON-LD script
console.log(
    makeSchemaTags(schema.createSchema('post', {site, meta: postMeta}))
);

Supported Schemas:

// type = 'author'
interface AuthorSchemaProperties {
    site: SiteData; // See `site` in the example
    meta: {
        name: string;
        url: string;
        description?: string;
        sameAs?: string[]; // must be full URLs
        image?: ImageObject; // see `site.image` in the example
    }
}

// type = 'home'
interface HomeSchemaProperties {
    name: string;
    site: SiteData;
    meta: {
        url: string;
        description?: string;
        image?: ImageObject;
    }
}

// type = 'post'
interface PostSchemaProperties {
    site: SiteData;
    author?: {
        name: string;
        url: string;
        sameAs?: string[];
        image?: ImageData;
        description?: string;
    };
    meta: {
        title: string;
        url: string;
        datePublished?: Date | string;
        dateModified?: Date | string;
        image?: ImageData;
        keywords?: string[];
        description?: string;
    }
}

// type = 'tag'
interface TagSchemaProperties {
    site: SiteData;
    meta: {
        name: string;
        url: string;
        image?: ImageObject;
        description?: string;
    }
}

Develop

This is a mono repository, managed with lerna.

Follow the instructions for the top-level repo. 1. git clone this repo & cd into it as usual 2. Run yarn to install top-level dependencies.

Run

  • yarn dev

Test

  • yarn lint run just eslint
  • yarn test run lint and tests

Copyright & License

Copyright (c) 2013-2023 Ghost Foundation - Released under the MIT license.

0.1.40

19 days ago

0.1.37

10 months ago

0.1.38

7 months ago

0.1.39

6 months ago

0.1.36

11 months ago

0.1.35

1 year ago

0.1.32

1 year ago

0.1.33

1 year ago

0.1.34

1 year ago

0.1.31

1 year ago

0.1.30

2 years ago

0.1.27

2 years ago

0.1.28

2 years ago

0.1.29

2 years ago

0.1.25

2 years ago

0.1.26

2 years ago

0.1.24

3 years ago

0.1.23

3 years ago

0.1.22

3 years ago

0.1.21

3 years ago

0.1.20

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.16

4 years ago

0.1.15

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago