@tryghost/schema-org 0.1.34 → 0.1.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -0
- package/SchemaGenerator.js +78 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -11,6 +11,113 @@ or
|
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
+
```js
|
|
15
|
+
const SchemaGenerator = require('@tryghost/schema-org');
|
|
16
|
+
|
|
17
|
+
const schema = new SchemaGenerator();
|
|
18
|
+
const makeSchemaTags = json => `<script type="application/ld+json">\n${json}\n</script>`;
|
|
19
|
+
|
|
20
|
+
// Schema data pertaining to the entire site
|
|
21
|
+
const site = {
|
|
22
|
+
title: 'Ghost',
|
|
23
|
+
url: 'https://demo.ghost.io',
|
|
24
|
+
image: {
|
|
25
|
+
url: 'https://static.ghost.org/v2.0.0/images/welcome-to-ghost.jpg',
|
|
26
|
+
// Optional!
|
|
27
|
+
dimensions: {
|
|
28
|
+
width: 1600,
|
|
29
|
+
height: 1050
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Example: generate schema for a post.
|
|
35
|
+
// Other supported options are `author`, `tag`, and `home`
|
|
36
|
+
const postObject = ghostPost(); // https://ghost.org/docs/api/v3/content/#posts
|
|
37
|
+
|
|
38
|
+
// Schema data pertaining to this specific resource
|
|
39
|
+
const postMeta = {
|
|
40
|
+
author: {
|
|
41
|
+
name: postObject.authors[0].name,
|
|
42
|
+
url: postObject.authors[0].url,
|
|
43
|
+
image: postObject.authors[0].profile_image,
|
|
44
|
+
description: postObject.authors[0].meta_description || postObject.authors[0].bio
|
|
45
|
+
},
|
|
46
|
+
meta: {
|
|
47
|
+
title: postObject.title,
|
|
48
|
+
url: postObject.url,
|
|
49
|
+
datePublished: postObject.published_at,
|
|
50
|
+
dateModified: postObject.updated_at,
|
|
51
|
+
image: postObject.feature_image,
|
|
52
|
+
keywords: postObject.tags.map(({name}) => name),
|
|
53
|
+
description: postObject.custom_excerpt || postObject.excerpt
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// Logs a valid JSON-LD script
|
|
58
|
+
console.log(
|
|
59
|
+
makeSchemaTags(schema.createSchema('post', {site, meta: postMeta}))
|
|
60
|
+
);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Supported Schemas:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// type = 'author'
|
|
67
|
+
interface AuthorSchemaProperties {
|
|
68
|
+
site: SiteData; // See `site` in the example
|
|
69
|
+
meta: {
|
|
70
|
+
name: string;
|
|
71
|
+
url: string;
|
|
72
|
+
description?: string;
|
|
73
|
+
sameAs?: string[]; // must be full URLs
|
|
74
|
+
image?: ImageObject; // see `site.image` in the example
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// type = 'home'
|
|
79
|
+
interface HomeSchemaProperties {
|
|
80
|
+
name: string;
|
|
81
|
+
site: SiteData;
|
|
82
|
+
meta: {
|
|
83
|
+
url: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
image?: ImageObject;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// type = 'post'
|
|
90
|
+
interface PostSchemaProperties {
|
|
91
|
+
site: SiteData;
|
|
92
|
+
author?: {
|
|
93
|
+
name: string;
|
|
94
|
+
url: string;
|
|
95
|
+
sameAs?: string[];
|
|
96
|
+
image?: ImageData;
|
|
97
|
+
description?: string;
|
|
98
|
+
};
|
|
99
|
+
meta: {
|
|
100
|
+
title: string;
|
|
101
|
+
url: string;
|
|
102
|
+
datePublished?: Date | string;
|
|
103
|
+
dateModified?: Date | string;
|
|
104
|
+
image?: ImageData;
|
|
105
|
+
keywords?: string[];
|
|
106
|
+
description?: string;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// type = 'tag'
|
|
111
|
+
interface TagSchemaProperties {
|
|
112
|
+
site: SiteData;
|
|
113
|
+
meta: {
|
|
114
|
+
name: string;
|
|
115
|
+
url: string;
|
|
116
|
+
image?: ImageObject;
|
|
117
|
+
description?: string;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
14
121
|
|
|
15
122
|
## Develop
|
|
16
123
|
|
package/SchemaGenerator.js
CHANGED
|
@@ -19,6 +19,80 @@ const trim = (schema) => {
|
|
|
19
19
|
return schema;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {{
|
|
24
|
+
* url?: string;
|
|
25
|
+
* title?: string;
|
|
26
|
+
* logo?: ImageObject
|
|
27
|
+
* }} SiteData
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
* @typedef {{
|
|
31
|
+
* url: string;
|
|
32
|
+
* dimensions?: {
|
|
33
|
+
* width?: number;
|
|
34
|
+
* height?: number;
|
|
35
|
+
* }
|
|
36
|
+
* }} DimensionalImage
|
|
37
|
+
*
|
|
38
|
+
* @typedef {DimensionalImage | string} ImageObject
|
|
39
|
+
*
|
|
40
|
+
*
|
|
41
|
+
* @typedef {{
|
|
42
|
+
* site: SiteData;
|
|
43
|
+
* meta: {
|
|
44
|
+
* name: string;
|
|
45
|
+
* url: string;
|
|
46
|
+
* description?: string;
|
|
47
|
+
* sameAs?: string[];
|
|
48
|
+
* image?: ImageObject;
|
|
49
|
+
* }
|
|
50
|
+
* }} AuthorSchemaProperties
|
|
51
|
+
*
|
|
52
|
+
*
|
|
53
|
+
* @typedef {{
|
|
54
|
+
* name: string;
|
|
55
|
+
* site: SiteData;
|
|
56
|
+
* meta: {
|
|
57
|
+
* url: string;
|
|
58
|
+
* description?: string;
|
|
59
|
+
* image?: ImageObject;
|
|
60
|
+
* }
|
|
61
|
+
* }} HomeSchemaProperties
|
|
62
|
+
*
|
|
63
|
+
*
|
|
64
|
+
* @typedef {{
|
|
65
|
+
* site: SiteData;
|
|
66
|
+
* author?: {
|
|
67
|
+
* name: string;
|
|
68
|
+
* url: string;
|
|
69
|
+
* sameAs?: string[];
|
|
70
|
+
* image?: ImageData;
|
|
71
|
+
* description?: string;
|
|
72
|
+
* }
|
|
73
|
+
* meta: {
|
|
74
|
+
* title: string;
|
|
75
|
+
* url: string;
|
|
76
|
+
* datePublished?: Date | string;
|
|
77
|
+
* dateModified?: Date | string;
|
|
78
|
+
* image?: ImageData;
|
|
79
|
+
* keywords?: string[];
|
|
80
|
+
* description?: string;
|
|
81
|
+
* }
|
|
82
|
+
* }} PostSchemaProperties
|
|
83
|
+
*
|
|
84
|
+
*
|
|
85
|
+
* @typedef {{
|
|
86
|
+
* site: SiteData;
|
|
87
|
+
* meta: {
|
|
88
|
+
* name: string;
|
|
89
|
+
* url: string;
|
|
90
|
+
* image?: ImageObject;
|
|
91
|
+
* description?: string;
|
|
92
|
+
* }
|
|
93
|
+
* }} TagSchemaProperties
|
|
94
|
+
*/
|
|
95
|
+
|
|
22
96
|
class SchemaGenerator {
|
|
23
97
|
constructor(options) {
|
|
24
98
|
this.options = options || {};
|
|
@@ -68,6 +142,10 @@ class SchemaGenerator {
|
|
|
68
142
|
return trim(json);
|
|
69
143
|
}
|
|
70
144
|
|
|
145
|
+
/**
|
|
146
|
+
* @param {'home' | 'author' | 'post' | 'tag'} type
|
|
147
|
+
* @param {HomeSchemaProperties | AuthorSchemaProperties | PostSchemaProperties | TagSchemaProperties} data
|
|
148
|
+
*/
|
|
71
149
|
createSchema(type, data) {
|
|
72
150
|
if (!_.has(this.templates, type)) {
|
|
73
151
|
type = 'home';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/schema-org",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.36",
|
|
4
4
|
"repository": "https://github.com/TryGhost/SDK/tree/master/packages/schema-org",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"istanbul": "0.4.5",
|
|
27
27
|
"mocha": "10.2.0",
|
|
28
28
|
"should": "13.2.3",
|
|
29
|
-
"sinon": "15.0.
|
|
29
|
+
"sinon": "15.0.4"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"glob": "^9.0.0",
|
|
33
33
|
"handlebars": "^4.7.7",
|
|
34
34
|
"lodash": "^4.17.11"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "60ab3c7b73d1d7d92987b7eb3d8e73f920dd6800"
|
|
37
37
|
}
|