@quintype/seo 1.41.0-canonical-toggle.0 → 1.41.1-gsc-errors.0
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/CHANGELOG.md +12 -0
- package/dist/index.cjs.js +9 -10
- package/index.js +34 -16
- package/package.json +1 -1
- package/src/amp-tags.js +27 -21
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [1.41.0](https://github.com/quintype/quintype-node-seo/compare/v1.40.15...v1.41.0) (2022-11-29)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **canonical:** Add canonical url toggle ([#539](https://github.com/quintype/quintype-node-seo/issues/539)) ([3c18124](https://github.com/quintype/quintype-node-seo/commit/3c181249b7adb06061a8a4c16aa71b640b21679c))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **canonical:** Toggle canonical tags ([1f8a4fe](https://github.com/quintype/quintype-node-seo/commit/1f8a4fe0955688080095275290dabe79dc6344d6))
|
|
16
|
+
|
|
5
17
|
### [1.40.15](https://github.com/quintype/quintype-node-seo/compare/v1.40.14...v1.40.15) (2022-11-17)
|
|
6
18
|
|
|
7
19
|
### [1.40.14](https://github.com/quintype/quintype-node-seo/compare/v1.40.11...v1.40.14) (2022-11-16)
|
package/dist/index.cjs.js
CHANGED
|
@@ -50,11 +50,11 @@ function isStoryPublic(story) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function showAmpTag({ ampStoryPages = true }, pageType, story) {
|
|
53
|
-
if (!ampStoryPages || pageType !==
|
|
53
|
+
if (!ampStoryPages || pageType !== "story-page") {
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
if (ampStoryPages ===
|
|
57
|
+
if (ampStoryPages === "public" && !isStoryPublic(story)) {
|
|
58
58
|
return false;
|
|
59
59
|
}
|
|
60
60
|
|
|
@@ -62,7 +62,7 @@ function showAmpTag({ ampStoryPages = true }, pageType, story) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const getDomain = (url, domainSlug) => {
|
|
65
|
-
const domain = domainSlug ? new URL(url).origin :
|
|
65
|
+
const domain = domainSlug ? new URL(url).origin : "";
|
|
66
66
|
try {
|
|
67
67
|
return domain;
|
|
68
68
|
} catch (err) {
|
|
@@ -81,18 +81,17 @@ const getDomain = (url, domainSlug) => {
|
|
|
81
81
|
* @param {...*} params See {@link Generator} for other Parameters
|
|
82
82
|
*/
|
|
83
83
|
function StoryAmpTags(seoConfig, config, pageType, data = {}, opts) {
|
|
84
|
-
|
|
85
84
|
const story = get__default["default"](data, ["data", "story"], {});
|
|
86
|
-
const { currentHostUrl =
|
|
85
|
+
const { currentHostUrl = "", domainSlug } = data;
|
|
87
86
|
// TODO: Remove this condition and always make absolute URL if that's better for AMP discoverability.
|
|
88
|
-
const ampUrlAppend = seoConfig.appendHostToAmpUrl ? getDomain(currentHostUrl, domainSlug) || config[
|
|
87
|
+
const ampUrlAppend = seoConfig.appendHostToAmpUrl ? getDomain(currentHostUrl, domainSlug) || config["sketches-host"] : "";
|
|
89
88
|
const storySlug = seoConfig.decodeAmpUrl ? decodeURIComponent(story.slug) : encodeURIComponent(story.slug);
|
|
90
89
|
const ampUrl = story["story-template"] === "visual-story" ? `${ampUrlAppend}/${storySlug}` : `${ampUrlAppend}/amp/story/${storySlug}`;
|
|
91
|
-
|
|
92
|
-
if (showAmpTag(seoConfig, pageType, story)) {
|
|
90
|
+
const ignoreStoryTemplate = seoConfig.ignoreAmpHtmlStoryTemplates && seoConfig.ignoreAmpHtmlStoryTemplates.includes(story["story-template"]);
|
|
91
|
+
if (showAmpTag(seoConfig, pageType, story) && !ignoreStoryTemplate) {
|
|
93
92
|
return [{
|
|
94
|
-
tag:
|
|
95
|
-
rel:
|
|
93
|
+
tag: "link",
|
|
94
|
+
rel: "amphtml",
|
|
96
95
|
href: ampUrl
|
|
97
96
|
}];
|
|
98
97
|
} else {
|
package/index.js
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
import { flatMap, get, omit, uniqBy } from "lodash";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import ReactDomServer from "react-dom/server";
|
|
4
|
-
import { StoryAmpTags } from
|
|
5
|
-
import { AuthorTags } from
|
|
6
|
-
import { generateStaticData, generateStructuredData } from
|
|
7
|
-
import { ImageTags } from
|
|
8
|
-
import { StaticTags } from
|
|
9
|
-
import { StructuredDataTags } from
|
|
10
|
-
import { getTitle, TextTags } from
|
|
4
|
+
import { StoryAmpTags } from "./src/amp-tags.js";
|
|
5
|
+
import { AuthorTags } from "./src/author-tags.js";
|
|
6
|
+
import { generateStaticData, generateStructuredData } from "./src/generate-common-seo";
|
|
7
|
+
import { ImageTags } from "./src/image-tags.js";
|
|
8
|
+
import { StaticTags } from "./src/static-tags.js";
|
|
9
|
+
import { StructuredDataTags } from "./src/structured-data/structured-data-tags.js";
|
|
10
|
+
import { getTitle, TextTags } from "./src/text-tags.js";
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
export {
|
|
13
|
+
TextTags,
|
|
14
|
+
StaticTags,
|
|
15
|
+
AuthorTags,
|
|
16
|
+
ImageTags,
|
|
17
|
+
StructuredDataTags,
|
|
18
|
+
StoryAmpTags,
|
|
19
|
+
generateStaticData,
|
|
20
|
+
generateStructuredData,
|
|
21
|
+
};
|
|
14
22
|
|
|
15
23
|
function tagToKey(tag) {
|
|
16
24
|
switch (tag.tag || "meta") {
|
|
17
|
-
case "meta":
|
|
18
|
-
|
|
19
|
-
case "
|
|
20
|
-
|
|
25
|
+
case "meta":
|
|
26
|
+
return `meta-${tag.name || tag.itemprop || "name"}-${tag.property || "property"}`;
|
|
27
|
+
case "link":
|
|
28
|
+
return `link-${tag.rel}`;
|
|
29
|
+
case "title":
|
|
30
|
+
return `title`;
|
|
31
|
+
default:
|
|
32
|
+
return Math.random().toString();
|
|
21
33
|
}
|
|
22
34
|
}
|
|
23
35
|
|
|
@@ -28,7 +40,9 @@ export class MetaTagList {
|
|
|
28
40
|
|
|
29
41
|
toString() {
|
|
30
42
|
const uniqueTags = uniqBy(this.tags.reverse(), tagToKey).reverse();
|
|
31
|
-
return ReactDomServer.renderToStaticMarkup(
|
|
43
|
+
return ReactDomServer.renderToStaticMarkup(
|
|
44
|
+
uniqueTags.map((tag) => React.createElement(tag.tag || "meta", omit(tag, "tag")))
|
|
45
|
+
);
|
|
32
46
|
}
|
|
33
47
|
|
|
34
48
|
addTag() {
|
|
@@ -93,12 +107,16 @@ export class SEO {
|
|
|
93
107
|
*/
|
|
94
108
|
constructor(seoConfig = {}) {
|
|
95
109
|
this.seoConfig = seoConfig;
|
|
96
|
-
this.generators = (
|
|
110
|
+
this.generators = (
|
|
111
|
+
seoConfig.generators || [TextTags, ImageTags, AuthorTags, StaticTags, StructuredDataTags, StoryAmpTags]
|
|
112
|
+
).concat(seoConfig.extraGenerators || []);
|
|
97
113
|
}
|
|
98
114
|
|
|
99
115
|
getMetaTags(config, pageType, data, params = {}) {
|
|
100
116
|
pageType = get(this.seoConfig, ["pageTypeAliases", pageType], pageType);
|
|
101
|
-
return new MetaTagList(
|
|
117
|
+
return new MetaTagList(
|
|
118
|
+
flatMap(this.generators, (generator) => generator(this.seoConfig, config, pageType, data, params))
|
|
119
|
+
);
|
|
102
120
|
}
|
|
103
121
|
|
|
104
122
|
getTitle(config, pageType, data, params = {}) {
|
package/package.json
CHANGED
package/src/amp-tags.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import get from
|
|
2
|
-
import { isStoryPublic } from
|
|
1
|
+
import get from "lodash/get";
|
|
2
|
+
import { isStoryPublic } from "./utils";
|
|
3
3
|
|
|
4
4
|
function showAmpTag({ ampStoryPages = true }, pageType, story) {
|
|
5
|
-
if (!ampStoryPages || pageType !==
|
|
5
|
+
if (!ampStoryPages || pageType !== "story-page") {
|
|
6
6
|
return false;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
if (ampStoryPages ===
|
|
9
|
+
if (ampStoryPages === "public" && !isStoryPublic(story)) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -14,14 +14,13 @@ function showAmpTag({ ampStoryPages = true }, pageType, story) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const getDomain = (url, domainSlug) => {
|
|
17
|
-
const domain = domainSlug ? new URL(url).origin :
|
|
17
|
+
const domain = domainSlug ? new URL(url).origin : "";
|
|
18
18
|
try {
|
|
19
19
|
return domain;
|
|
20
|
+
} catch (err) {
|
|
21
|
+
return "";
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
return ""
|
|
23
|
-
}
|
|
24
|
-
}
|
|
23
|
+
};
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* StoryAmpTags adds the amphref to stories which support amp.
|
|
@@ -34,20 +33,27 @@ const getDomain = (url, domainSlug) => {
|
|
|
34
33
|
* @param {...*} params See {@link Generator} for other Parameters
|
|
35
34
|
*/
|
|
36
35
|
export function StoryAmpTags(seoConfig, config, pageType, data = {}, opts) {
|
|
37
|
-
|
|
38
36
|
const story = get(data, ["data", "story"], {});
|
|
39
|
-
const { currentHostUrl =
|
|
37
|
+
const { currentHostUrl = "", domainSlug } = data;
|
|
40
38
|
// TODO: Remove this condition and always make absolute URL if that's better for AMP discoverability.
|
|
41
|
-
const ampUrlAppend = seoConfig.appendHostToAmpUrl
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
39
|
+
const ampUrlAppend = seoConfig.appendHostToAmpUrl
|
|
40
|
+
? getDomain(currentHostUrl, domainSlug) || config["sketches-host"]
|
|
41
|
+
: "";
|
|
42
|
+
const storySlug = seoConfig.decodeAmpUrl ? decodeURIComponent(story.slug) : encodeURIComponent(story.slug);
|
|
43
|
+
const ampUrl =
|
|
44
|
+
story["story-template"] === "visual-story"
|
|
45
|
+
? `${ampUrlAppend}/${storySlug}`
|
|
46
|
+
: `${ampUrlAppend}/amp/story/${storySlug}`;
|
|
47
|
+
const ignoreStoryTemplate =
|
|
48
|
+
seoConfig.ignoreAmpHtmlStoryTemplates && seoConfig.ignoreAmpHtmlStoryTemplates.includes(story["story-template"]);
|
|
49
|
+
if (showAmpTag(seoConfig, pageType, story) && !ignoreStoryTemplate) {
|
|
50
|
+
return [
|
|
51
|
+
{
|
|
52
|
+
tag: "link",
|
|
53
|
+
rel: "amphtml",
|
|
54
|
+
href: ampUrl,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
51
57
|
} else {
|
|
52
58
|
return [];
|
|
53
59
|
}
|