gatsby-core-theme 44.0.39 → 44.0.40
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 +21 -0
- package/gatsby-node.mjs +1 -1
- package/package.json +1 -1
- package/src/components/organisms/head/customData.js +1 -0
- package/src/components/organisms/head/head.test.js +21 -57
- package/src/components/organisms/head/index.js +38 -81
- package/src/constants/metaTags.js +15 -0
- package/src/helpers/getters.mjs +7 -1
- package/src/helpers/getters.test.js +30 -0
- package/src/helpers/head.js +51 -0
- package/src/helpers/head.test.js +50 -0
- package/src/helpers/schema.js +7 -4
- package/src/helpers/schema.test.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [44.0.40](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.0.39...v44.0.40) (2025-05-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add customeData ([b5936fa](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/b5936fac9e928cd78b70f48a2521ba9eb6118c20))
|
|
7
|
+
* add validation for archive pages ([5561b9c](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/5561b9c2540ffe7f9917e6c2cba4d3cec7055e67))
|
|
8
|
+
* centralaize the meta data ([3a21c76](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/3a21c76f694482f587a31e26bd64eb8bbd5f78b1))
|
|
9
|
+
* clean up the function ([91773ef](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/91773ef08cc1b40b5ca388715941eb033f3ae466))
|
|
10
|
+
* fix aleternative links default ([e97e985](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/e97e9854498f669c423597b4d68c9f6d8ff105a5))
|
|
11
|
+
* fix issues ([dbcfcec](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/dbcfcec545657a18ac35296033933a7728b6b0fd))
|
|
12
|
+
* fix meta data ([c29976b](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/c29976bf95cc763695099ceec8044f5066a17dfa))
|
|
13
|
+
* fix test ([3711007](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/3711007e4427f057ff3a0a0019e19836aae1e304))
|
|
14
|
+
* update meta data ([2888046](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/2888046a7c512fc01d83159f06ab48be6f6d1546))
|
|
15
|
+
* update the schema ([8eda362](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/8eda362674e2fa2cf2e2f40d37a067944163e0f2))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
* Merge branch 'tm-5213-head' into 'master' ([90fb1d7](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/90fb1d793113ffbda45ea6dc4f43bbcfd5052424))
|
|
19
|
+
* Merge branch 'master' into 'tm-5213-head' ([28a6b72](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/28a6b72f1c15bca3bd755ba93863df48d0b91e9a))
|
|
20
|
+
* Merge branch 'master' into tm-5213-head ([a14780f](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/a14780ff0d5b36080e94970c6ad674660c255f9e))
|
|
21
|
+
|
|
1
22
|
## [44.0.39](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.0.38...v44.0.39) (2025-05-15)
|
|
2
23
|
|
|
3
24
|
|
package/gatsby-node.mjs
CHANGED
|
@@ -88,7 +88,7 @@ function createArchivePage(
|
|
|
88
88
|
|
|
89
89
|
if (process.env.CUSTOM_CONTENT_PAGES_PATH && archivePages) {
|
|
90
90
|
// eslint-disable-next-line array-callback-return
|
|
91
|
-
archivePages = archivePages.filter((item) => {
|
|
91
|
+
archivePages = archivePages && archivePages.filter((item) => {
|
|
92
92
|
if (item.path.includes(process.env.CUSTOM_CONTENT_PAGES_PATH)) {
|
|
93
93
|
return item;
|
|
94
94
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function customData() {}
|
|
@@ -1,76 +1,40 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { render, cleanup, waitFor } from
|
|
3
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render, cleanup, waitFor } from "@testing-library/react";
|
|
3
|
+
import "@testing-library/jest-dom/extend-expect";
|
|
4
4
|
|
|
5
|
-
import Head
|
|
5
|
+
import Head from ".";
|
|
6
6
|
|
|
7
|
-
describe(
|
|
8
|
-
test(
|
|
9
|
-
expect(getLanguage('str')).toEqual('str');
|
|
10
|
-
expect(getLanguage('')).toEqual('en');
|
|
11
|
-
expect(getLanguage('no')).toEqual('nb-NO');
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('getCanonicalUrl()', () => {
|
|
15
|
-
expect(getCanonicalUrl({ path: '/' })).toEqual(process.env.GATSBY_SITE_URL);
|
|
16
|
-
expect(getCanonicalUrl({ path: 'sdsdasdsajkdhjkashk' })).toEqual(
|
|
17
|
-
`${process.env.GATSBY_SITE_URL}sdsdasdsajkdhjkashk`
|
|
18
|
-
);
|
|
19
|
-
expect(getCanonicalUrl({ path: 'about', canonical_url: 'contact' })).toEqual(
|
|
20
|
-
`${process.env.GATSBY_SITE_URL}contact`
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('getRobotOptions()', () => {
|
|
25
|
-
const arrOne = {
|
|
26
|
-
page_index: 0,
|
|
27
|
-
links_followed: 0,
|
|
28
|
-
images_index: 0,
|
|
29
|
-
show_snippet: 0,
|
|
30
|
-
};
|
|
31
|
-
expect(getRobotOptions(arrOne)).toEqual('noindex,nofollow,noimageindex,nosnippet');
|
|
32
|
-
arrOne.page_index = 1;
|
|
33
|
-
arrOne.show_snippet = 1;
|
|
34
|
-
expect(getRobotOptions(arrOne)).toEqual('nofollow,noimageindex');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('render with props', async () => {
|
|
7
|
+
describe("Head Component", () => {
|
|
8
|
+
test("render with props", async () => {
|
|
38
9
|
const { container } = render(
|
|
39
10
|
<Head
|
|
40
11
|
siteInfo={{
|
|
41
|
-
site_name:
|
|
42
|
-
site_logo:
|
|
12
|
+
site_name: "test",
|
|
13
|
+
site_logo: "#",
|
|
43
14
|
}}
|
|
44
15
|
page={{
|
|
45
|
-
meta_title:
|
|
46
|
-
language:
|
|
47
|
-
meta_description:
|
|
48
|
-
meta_robots: [
|
|
49
|
-
path:
|
|
50
|
-
preconnect_links: [
|
|
16
|
+
meta_title: "my meta title",
|
|
17
|
+
language: "en",
|
|
18
|
+
meta_description: "my meta description",
|
|
19
|
+
meta_robots: ["one", "two", "three"],
|
|
20
|
+
path: "my path",
|
|
21
|
+
preconnect_links: ["1", "2", "3"],
|
|
51
22
|
seo_json_schema: [],
|
|
52
23
|
sections: { main: {} },
|
|
24
|
+
robot_options: { page_index: 1 },
|
|
53
25
|
}}
|
|
54
26
|
/>
|
|
55
27
|
);
|
|
28
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
56
29
|
expect(container).toBeTruthy();
|
|
57
30
|
await waitFor(() => {
|
|
58
|
-
expect(document.title).toEqual(
|
|
31
|
+
expect(document.title).toEqual("my meta title");
|
|
59
32
|
// expect(document.documentElement.lang).toEqual('en');
|
|
60
|
-
expect(document.querySelectorAll(
|
|
61
|
-
expect(
|
|
62
|
-
|
|
63
|
-
);
|
|
64
|
-
expect(document.getElementsByTagName('meta')[1].getAttribute('content')).toEqual(
|
|
65
|
-
'one,two,three'
|
|
66
|
-
);
|
|
33
|
+
expect(document.querySelectorAll("link[rel=preconnect]")).toHaveLength(3);
|
|
34
|
+
expect(
|
|
35
|
+
document.getElementsByTagName("meta")[0].getAttribute("content")
|
|
36
|
+
).toEqual("my meta description");
|
|
67
37
|
|
|
68
|
-
expect(document.querySelector("meta[name='og:title']").getAttribute('content')).toEqual(
|
|
69
|
-
'my meta title'
|
|
70
|
-
);
|
|
71
|
-
// expect(document.querySelector('meta[name=og:site_name]').getAttribute('content')).toEqual(
|
|
72
|
-
// 'test'
|
|
73
|
-
// );
|
|
74
38
|
});
|
|
75
39
|
});
|
|
76
40
|
});
|
|
@@ -1,95 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import { schemaGenerator } from
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (process.env.GATSBY_SITE_LANG) return process.env.GATSBY_SITE_LANG;
|
|
10
|
-
if (language === 'no') return 'nb-NO';
|
|
11
|
-
return language || 'en';
|
|
12
|
-
}
|
|
13
|
-
export function getCanonicalUrl(page, isTracker) {
|
|
14
|
-
if (page.canonical_url) {
|
|
15
|
-
return `${process.env.GATSBY_SITE_URL}${page.canonical_url}`;
|
|
16
|
-
}
|
|
17
|
-
if (page.path === '/') {
|
|
18
|
-
return process.env.GATSBY_SITE_URL;
|
|
19
|
-
}
|
|
20
|
-
const trailingSlash = process.env.TRAILING_SLASH ? '/' : '';
|
|
21
|
-
|
|
22
|
-
return `${process.env.GATSBY_SITE_URL}${page.path.replace(/^\//, '')}${
|
|
23
|
-
!isTracker ? trailingSlash : ''
|
|
24
|
-
}`
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
export function getRobotOptions(options) {
|
|
28
|
-
const array = [];
|
|
29
|
-
if (!options.page_index && process.env.GATSBY_ACTIVE_ENV !== 'development') array.push('noindex');
|
|
30
|
-
if (!options.links_followed && process.env.GATSBY_ACTIVE_ENV !== 'development')
|
|
31
|
-
array.push('nofollow');
|
|
32
|
-
if (!options.images_index && process.env.GATSBY_ACTIVE_ENV !== 'development')
|
|
33
|
-
array.push('noimageindex');
|
|
34
|
-
if (!options.show_snippet && process.env.GATSBY_ACTIVE_ENV !== 'development')
|
|
35
|
-
array.push('nosnippet');
|
|
36
|
-
if (process.env.GATSBY_ACTIVE_ENV === 'development') array.push('noindex,follow');
|
|
37
|
-
return array.join();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function setName(string) {
|
|
41
|
-
const [name] = string.split('.');
|
|
42
|
-
return name[0].toUpperCase() + name.slice(1);
|
|
43
|
-
}
|
|
1
|
+
/* eslint-disable no-unused-vars */
|
|
2
|
+
import React from "react";
|
|
3
|
+
import PropTypes from "prop-types";
|
|
4
|
+
import { schemaGenerator } from "~helpers/schema";
|
|
5
|
+
import keygen from "~helpers/keygen";
|
|
6
|
+
import { getUrl, getLanguage } from "~helpers/getters";
|
|
7
|
+
import { getMetaTags, getCanonicalUrl } from "~helpers/head";
|
|
8
|
+
import customData from "./customData";
|
|
44
9
|
|
|
45
10
|
const HeadData = ({ page = {}, siteInfo }) => {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
11
|
+
const isTracker = page.template === "tracker";
|
|
12
|
+
const metaTags = getMetaTags(page, siteInfo, isTracker);
|
|
48
13
|
let defaultHref = null;
|
|
49
|
-
|
|
14
|
+
|
|
50
15
|
return (
|
|
51
16
|
<>
|
|
52
17
|
<title>{page.meta_title}</title>
|
|
53
18
|
<html lang={getLanguage(page.language)} />
|
|
54
|
-
|
|
55
|
-
{
|
|
56
|
-
|
|
57
|
-
)}
|
|
58
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
59
|
-
|
|
60
|
-
{page.robot_options && <meta name="robots" content={getRobotOptions(page.robot_options)} />}
|
|
61
|
-
|
|
62
|
-
{process.env.GATSBY_ACTIVE_ENV === 'development' && (
|
|
19
|
+
{metaTags}
|
|
20
|
+
{customData()}
|
|
21
|
+
{process.env.GATSBY_ACTIVE_ENV === "development" && (
|
|
63
22
|
<meta name="googlebot" content="noindex,follow" />
|
|
64
23
|
)}
|
|
65
|
-
<link rel="canonical" href={getCanonicalUrl(page, isTracker)}
|
|
66
|
-
{page?.hreflangs?.map((link) => {
|
|
67
|
-
if (link?.default)
|
|
68
|
-
|
|
24
|
+
<link rel="canonical" href={getCanonicalUrl(page, isTracker)} />\
|
|
25
|
+
{page?.hreflangs?.map((link) => {
|
|
26
|
+
if (link?.default) {
|
|
27
|
+
defaultHref = link?.path;
|
|
28
|
+
}
|
|
29
|
+
return (
|
|
30
|
+
<link
|
|
31
|
+
key={keygen()}
|
|
32
|
+
rel="alternate"
|
|
33
|
+
href={getUrl(link.path)}
|
|
34
|
+
hrefLang={link.language}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
69
37
|
})}
|
|
70
|
-
{defaultHref &&
|
|
71
|
-
|
|
72
|
-
{page.preconnect_links &&
|
|
73
|
-
page.preconnect_links.map((link) => <link key={keygen()} rel="preconnect" href={link} />)}
|
|
74
|
-
<meta name="og:title" content={page.meta_title} />
|
|
75
|
-
<meta name="og:site_name" content={siteInfo?.site_name && setName(siteInfo?.site_name)} />
|
|
76
|
-
<meta name="og:description" content={page.meta_description} />
|
|
77
|
-
<meta name="og:type" content={page.path === '/' ? 'website' : 'article'} />
|
|
78
|
-
<meta name="og:image" content={pageImage} />
|
|
79
|
-
<meta name="og:url" content={getCanonicalUrl(page, isTracker)} />
|
|
80
|
-
<meta
|
|
81
|
-
property="og:locale"
|
|
82
|
-
content={getLanguage(page.language) === 'en' ? 'en_GB' : getLanguage(page.language)}
|
|
83
|
-
/>
|
|
84
|
-
|
|
85
|
-
{schemaGenerator(page, pageImage).map(
|
|
86
|
-
(schema) =>
|
|
87
|
-
schema && (
|
|
88
|
-
<script key={keygen()} type="application/ld+json">
|
|
89
|
-
{`${schema}`}
|
|
90
|
-
</script>
|
|
91
|
-
)
|
|
38
|
+
{defaultHref && (
|
|
39
|
+
<link rel="alternate" href={getUrl(defaultHref)} hrefLang="x-default" />
|
|
92
40
|
)}
|
|
41
|
+
{page.preconnect_links &&
|
|
42
|
+
page.preconnect_links.map((link) => (
|
|
43
|
+
<link key={keygen()} rel="preconnect" href={link} />
|
|
44
|
+
))}
|
|
45
|
+
{schemaGenerator(page, getUrl(page.path)).map((schema) => (
|
|
46
|
+
<script key={keygen()} type="application/ld+json">
|
|
47
|
+
{`${schema}`}
|
|
48
|
+
</script>
|
|
49
|
+
))}
|
|
93
50
|
</>
|
|
94
51
|
);
|
|
95
52
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getLanguage,setName } from '~helpers/getters';
|
|
2
|
+
import { getRobotOptions, getCanonicalUrl } from '~helpers/head';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export default (page, siteInfo, pageImage, isTracker) => [
|
|
6
|
+
{ type: "meta", name: "description", content: page.meta_description },
|
|
7
|
+
{ type: "meta", name: "robots", content: getRobotOptions(page.robot_options) },
|
|
8
|
+
{ type: "meta", property: "og:title", content: page.meta_title },
|
|
9
|
+
{ type: "meta", property: "og:site_name", content: siteInfo?.site_name ? setName(siteInfo.site_name) : "" },
|
|
10
|
+
{ type: "meta", property: "og:description", content: page.meta_description },
|
|
11
|
+
{ type: "meta", property: "og:type", content: page.path === '/' ? 'website' : 'article' },
|
|
12
|
+
{ type: "meta", property: "og:image", content: pageImage },
|
|
13
|
+
{ type: "meta", property: "og:url", content: getCanonicalUrl(page, isTracker) },
|
|
14
|
+
{ type: "meta", property: "og:locale", content: getLanguage(page.language) === 'en' ? 'en_GB' : getLanguage(page.language) },
|
|
15
|
+
];
|
package/src/helpers/getters.mjs
CHANGED
|
@@ -363,10 +363,11 @@ export function getUrl(path) {
|
|
|
363
363
|
return process.env.GATSBY_SITE_URL;
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
return `${process.env.GATSBY_SITE_URL}${path.replace(/^\//, "")}`;
|
|
366
|
+
return `${process.env.GATSBY_SITE_URL}${path.replace(/^\//, "")}${process.env.TRALING_SLASH ? "/" : ""}`;
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
export function getLanguage(language) {
|
|
370
|
+
if (process.env.GATSBY_SITE_LANG) return process.env.GATSBY_SITE_LANG;
|
|
370
371
|
if (language === "no") return "nb-NO";
|
|
371
372
|
return language || "en";
|
|
372
373
|
}
|
|
@@ -534,6 +535,11 @@ export const filterNonNullValues = (data) =>
|
|
|
534
535
|
return acc;
|
|
535
536
|
}, {});
|
|
536
537
|
|
|
538
|
+
|
|
539
|
+
export function setName(string) {
|
|
540
|
+
const [name] = string.split(".");
|
|
541
|
+
return name[0].toUpperCase() + name.slice(1);
|
|
542
|
+
}
|
|
537
543
|
export const trailingSlash = (content) => {
|
|
538
544
|
if (!content || process.env.TRAILING_SLASH !== "true") return content;
|
|
539
545
|
|
|
@@ -457,6 +457,36 @@ describe('Getters Helper', () => {
|
|
|
457
457
|
const expected = { a: 1, c: 2 };
|
|
458
458
|
expect(Getters.filterNonNullValues(input)).toEqual(expected);
|
|
459
459
|
});
|
|
460
|
+
|
|
461
|
+
describe('getLanguage', () => {
|
|
462
|
+
it('returns GATSBY_SITE_LANG if set', () => {
|
|
463
|
+
process.env.GATSBY_SITE_LANG = 'fr';
|
|
464
|
+
expect(Getters.getLanguage('en')).toBe('fr');
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it('returns "nb-NO" if language is "no"', () => {
|
|
468
|
+
delete process.env.GATSBY_SITE_LANG;
|
|
469
|
+
expect(Getters.getLanguage('no')).toBe('nb-NO');
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it('returns provided language if GATSBY_SITE_LANG is not set', () => {
|
|
473
|
+
delete process.env.GATSBY_SITE_LANG;
|
|
474
|
+
expect(Getters.getLanguage('es')).toBe('es');
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
it('returns "en" if no language is provided', () => {
|
|
478
|
+
delete process.env.GATSBY_SITE_LANG;
|
|
479
|
+
expect(Getters.getLanguage()).toBe('en');
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
describe('setName', () => {
|
|
484
|
+
it('returns capitalized name from string', () => {
|
|
485
|
+
expect(Getters.setName('example.com')).toBe('Example');
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
|
|
460
490
|
test('basic functionality with sample HTML', () => {
|
|
461
491
|
process.env.TRAILING_SLASH = 'true';
|
|
462
492
|
process.env.GATSBY_SITE_URL = 'https://demo-gatsby-theme.gigmedia.com/';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { getPageImage, imagePrettyUrl } from "~helpers/getters";
|
|
3
|
+
import keygen from "~helpers/keygen";
|
|
4
|
+
import metaTags from "~constants/metaTags";
|
|
5
|
+
|
|
6
|
+
export const getMetaTags = (page, siteInfo, isTracker) => {
|
|
7
|
+
const pageImage = getPageImage(page) || imagePrettyUrl(siteInfo?.site_logo);
|
|
8
|
+
return metaTags(page, siteInfo, pageImage, isTracker).map((meta) => (
|
|
9
|
+
<meta
|
|
10
|
+
key={keygen()}
|
|
11
|
+
{...(meta.name ? { name: meta.name } : { property: meta.property })}
|
|
12
|
+
content={meta.content}
|
|
13
|
+
/>
|
|
14
|
+
));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function getCanonicalUrl(page, isTracker) {
|
|
18
|
+
if (page.canonical_url) {
|
|
19
|
+
return `${process.env.GATSBY_SITE_URL}${page.canonical_url}`;
|
|
20
|
+
}
|
|
21
|
+
if (page.path === "/") {
|
|
22
|
+
return process.env.GATSBY_SITE_URL;
|
|
23
|
+
}
|
|
24
|
+
const trailingSlash = process.env.TRAILING_SLASH ? "/" : "";
|
|
25
|
+
|
|
26
|
+
return `${process.env.GATSBY_SITE_URL}${page.path.replace(/^\//, "")}${
|
|
27
|
+
!isTracker ? trailingSlash : ""
|
|
28
|
+
}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getRobotOptions(options) {
|
|
32
|
+
const array = [];
|
|
33
|
+
if (
|
|
34
|
+
!options &&
|
|
35
|
+
!options.page_index &&
|
|
36
|
+
process.env.GATSBY_ACTIVE_ENV !== "development"
|
|
37
|
+
)
|
|
38
|
+
array.push("noindex");
|
|
39
|
+
if (
|
|
40
|
+
!options.links_followed &&
|
|
41
|
+
process.env.GATSBY_ACTIVE_ENV !== "development"
|
|
42
|
+
)
|
|
43
|
+
array.push("nofollow");
|
|
44
|
+
if (!options.images_index && process.env.GATSBY_ACTIVE_ENV !== "development")
|
|
45
|
+
array.push("noimageindex");
|
|
46
|
+
if (!options.show_snippet && process.env.GATSBY_ACTIVE_ENV !== "development")
|
|
47
|
+
array.push("nosnippet");
|
|
48
|
+
if (process.env.GATSBY_ACTIVE_ENV === "development")
|
|
49
|
+
array.push("noindex,follow");
|
|
50
|
+
return array.join();
|
|
51
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {getMetaTags, getCanonicalUrl} from './head';
|
|
2
|
+
|
|
3
|
+
describe('head.js functions', () => {
|
|
4
|
+
describe('getMetaTags', () => {
|
|
5
|
+
it('returns meta tags correctly', () => {
|
|
6
|
+
const page = {
|
|
7
|
+
robot_options: { page_index: 1 },
|
|
8
|
+
path:"/"
|
|
9
|
+
};
|
|
10
|
+
const siteInfo = { site_logo: 'logo.png' };
|
|
11
|
+
const isTracker = false;
|
|
12
|
+
|
|
13
|
+
const result = getMetaTags(page, siteInfo, isTracker);
|
|
14
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
15
|
+
expect(result).toBeTruthy();
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('getCanonicalUrl', () => {
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
process.env.GATSBY_SITE_URL = 'https://example.com';
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('returns canonical_url if set', () => {
|
|
25
|
+
const page = { canonical_url: 'canonical' };
|
|
26
|
+
process.env.GATSBY_SITE_URL = 'https://example.com/';
|
|
27
|
+
expect(getCanonicalUrl(page, false)).toBe('https://example.com/canonical');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('returns site URL if page path is "/"', () => {
|
|
31
|
+
const page = { path: '/' };
|
|
32
|
+
process.env.GATSBY_SITE_URL = 'https://example.com/';
|
|
33
|
+
expect(getCanonicalUrl(page, false)).toBe('https://example.com/');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('returns URL with trailing slash if TRAILING_SLASH is set', () => {
|
|
37
|
+
process.env.TRAILING_SLASH = 'true';
|
|
38
|
+
process.env.GATSBY_SITE_URL = 'https://example.com/';
|
|
39
|
+
const page = { path: 'about' };
|
|
40
|
+
expect(getCanonicalUrl(page, false)).toBe('https://example.com/about/');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('returns URL without trailing slash if TRAILING_SLASH is not set', () => {
|
|
44
|
+
delete process.env.TRAILING_SLASH;
|
|
45
|
+
process.env.GATSBY_SITE_URL = 'https://example.com/';
|
|
46
|
+
const page = { path: 'about' };
|
|
47
|
+
expect(getCanonicalUrl(page, false)).toBe('https://example.com/about');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
package/src/helpers/schema.js
CHANGED
|
@@ -109,6 +109,9 @@ export const prosAndConsData = (pageObj) => {
|
|
|
109
109
|
const prosAndConstObj =
|
|
110
110
|
pageObj?.sections?.main?.modules?.find((elm) => elm?.name === 'pros_and_cons') || {};
|
|
111
111
|
|
|
112
|
+
const anchroUrl = prosAndConstObj?.anchored ? prosAndConstObj?.anchor_slug : '';
|
|
113
|
+
|
|
114
|
+
|
|
112
115
|
// There are url keys because it is required
|
|
113
116
|
// otherwise it would throw errors
|
|
114
117
|
return (
|
|
@@ -120,8 +123,8 @@ export const prosAndConsData = (pageObj) => {
|
|
|
120
123
|
prosAndConstObj?.pros?.map((elm, index) => ({
|
|
121
124
|
'@type': 'ListItem',
|
|
122
125
|
position: index + 1,
|
|
123
|
-
url: `${getUrl('/')}#${elm}`,
|
|
124
126
|
name: elm,
|
|
127
|
+
url: `${getUrl('/')}${anchroUrl ? `#${anchroUrl}` : ''}`
|
|
125
128
|
})) || [],
|
|
126
129
|
},
|
|
127
130
|
}),
|
|
@@ -132,7 +135,7 @@ export const prosAndConsData = (pageObj) => {
|
|
|
132
135
|
prosAndConstObj?.cons?.map((elm, index) => ({
|
|
133
136
|
'@type': 'ListItem',
|
|
134
137
|
position: index + 1,
|
|
135
|
-
url: `${getUrl('/')}
|
|
138
|
+
url: `${getUrl('/')}${anchroUrl ? `#${anchroUrl}` : ''}`,
|
|
136
139
|
name: elm,
|
|
137
140
|
})) || [],
|
|
138
141
|
},
|
|
@@ -422,7 +425,7 @@ export function templateSchemas(page, pageImage) {
|
|
|
422
425
|
|
|
423
426
|
return JSON.stringify(generateSchemaObject(schema));
|
|
424
427
|
}
|
|
425
|
-
case 'operator': {
|
|
428
|
+
case 'operator': {
|
|
426
429
|
const schema = {
|
|
427
430
|
'@context': 'https://schema.org',
|
|
428
431
|
'@type': 'Review',
|
|
@@ -434,7 +437,7 @@ export function templateSchemas(page, pageImage) {
|
|
|
434
437
|
'@type': 'Organization',
|
|
435
438
|
url: getUrl(page.path),
|
|
436
439
|
name: page.title || '',
|
|
437
|
-
image: page.relation?.logo?.filename,
|
|
440
|
+
image: imagePrettyUrl(page.relation?.logo?.filename),
|
|
438
441
|
},
|
|
439
442
|
reviewRating: {
|
|
440
443
|
'@type': 'Rating',
|
|
@@ -466,7 +466,7 @@ describe('Schema Helper', () => {
|
|
|
466
466
|
expect(json.itemReviewed['@type']).toEqual('Organization');
|
|
467
467
|
expect(json.itemReviewed.url).toEqual(getUrl('operator_page'));
|
|
468
468
|
expect(json.itemReviewed.name).toEqual('Operator Title');
|
|
469
|
-
expect(json.itemReviewed.image).toEqual('logo_url/image.jpg');
|
|
469
|
+
expect(json.itemReviewed.image).toEqual('https://cdn.images.com/logo_url/image.jpg');
|
|
470
470
|
|
|
471
471
|
expect(Object.prototype.toString.call(json.reviewRating)).toEqual('[object Object]');
|
|
472
472
|
expect(json.reviewRating['@type']).toEqual('Rating');
|