@anywayseo/gatsby-plugin 2.7.0 → 2.8.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@anywayseo/gatsby-plugin",
3
3
  "description": "Shared config for Anywayseo sites",
4
- "version": "2.7.0",
4
+ "version": "2.8.1",
5
5
  "author": "zerg41",
6
6
  "license": "MIT",
7
7
  "publishConfig": {
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createMdxPages = createMdxPages;
13
13
  const path_1 = require("path");
14
- const slug_1 = require("../slug");
14
+ const slug_1 = require("../utils/slug");
15
15
  function createMdxPages(_a, root_1) {
16
16
  return __awaiter(this, arguments, void 0, function* ({ actions, reporter, graphql }, root) {
17
17
  var _b, _c, _d, _e, _f, _g;
@@ -33,6 +33,9 @@ function createMdxPages(_a, root_1) {
33
33
  allStrapiPage {
34
34
  nodes {
35
35
  slug
36
+ hub {
37
+ slug
38
+ }
36
39
  }
37
40
  }
38
41
  }
@@ -52,7 +55,7 @@ function createMdxPages(_a, root_1) {
52
55
  const slug = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.slug;
53
56
  const contentFilePath = internal.contentFilePath;
54
57
  if (slug && contentFilePath) {
55
- const existingPage = strapiPages.find((strapiPage) => (0, slug_1.isEqualSlug)(strapiPage === null || strapiPage === void 0 ? void 0 : strapiPage.slug, slug));
58
+ const existingPage = strapiPages.find((strapiPage) => { var _a; return (0, slug_1.isEqualSlug)((0, slug_1.mergeSlug)(strapiPage.slug, (_a = strapiPage.hub) === null || _a === void 0 ? void 0 : _a.slug), slug); });
56
59
  if (!!existingPage) {
57
60
  reporter.warn(`Skipping MDX page creation: "${slug}" already exists`);
58
61
  return;
@@ -13,6 +13,9 @@ export interface IGetAllMdxPageQuery {
13
13
  allStrapiPage?: {
14
14
  nodes: {
15
15
  slug?: string | null;
16
+ hub?: {
17
+ slug?: string | null;
18
+ } | null;
16
19
  }[];
17
20
  };
18
21
  }
@@ -11,7 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createStrapiPages = createStrapiPages;
13
13
  const path_1 = require("path");
14
- const slug_1 = require("../slug");
14
+ const slug_1 = require("../utils/slug");
15
+ const hreflang_1 = require("../utils/hreflang");
15
16
  function createStrapiPages(_a, root_1) {
16
17
  return __awaiter(this, arguments, void 0, function* ({ actions, reporter, graphql }, root) {
17
18
  var _b, _c, _d, _e;
@@ -28,6 +29,9 @@ function createStrapiPages(_a, root_1) {
28
29
  title
29
30
  slug
30
31
  locale
32
+ hub {
33
+ slug
34
+ }
31
35
  }
32
36
  }
33
37
  }
@@ -42,8 +46,11 @@ function createStrapiPages(_a, root_1) {
42
46
  return;
43
47
  }
44
48
  reporter.info(`Found ${strapiPages.length} Strapi pages`);
49
+ const hrefLangMap = (0, hreflang_1.buildHrefLangMap)(strapiPages, defaultLocale);
50
+ reporter.info(`Generated hrefLangs for Strapi pages`);
45
51
  let pageCount = 0;
46
- strapiPages.forEach(({ id, slug, title, locale }) => {
52
+ strapiPages.forEach(({ id, slug, title, locale, hub }) => {
53
+ var _a;
47
54
  if ((0, slug_1.isDummyPage)(slug)) {
48
55
  reporter.warn('Skipping page creation: dummy page detected');
49
56
  return;
@@ -53,10 +60,12 @@ function createStrapiPages(_a, root_1) {
53
60
  return;
54
61
  }
55
62
  const strapiPageTemplate = (0, path_1.resolve)(root, `./src/templates/strapi-page.tsx`);
63
+ const strapiPagePath = (0, slug_1.buildPath)((0, slug_1.mergeSlug)(slug, hub === null || hub === void 0 ? void 0 : hub.slug), locale, defaultLocale);
64
+ const strapiPageHrefLangs = (_a = hrefLangMap[strapiPagePath]) !== null && _a !== void 0 ? _a : [];
56
65
  actions.createPage({
57
- path: (0, slug_1.buildPath)(slug, locale, defaultLocale),
66
+ path: strapiPagePath,
58
67
  component: strapiPageTemplate,
59
- context: { id },
68
+ context: { id, hrefLangs: strapiPageHrefLangs },
60
69
  });
61
70
  pageCount++;
62
71
  });
@@ -8,6 +8,9 @@ export interface IGetAllStrapiPageQuery {
8
8
  title?: string | null;
9
9
  slug?: string | null;
10
10
  locale?: string | null;
11
+ hub?: {
12
+ slug?: string | null;
13
+ } | null;
11
14
  }[];
12
15
  };
13
16
  }
@@ -0,0 +1,2 @@
1
+ import type { HrefLangMap, IPage } from './types';
2
+ export declare function buildHrefLangMap(pages: IPage[], defaultLocale?: string): HrefLangMap;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildHrefLangMap = buildHrefLangMap;
4
+ const slug_1 = require("./slug");
5
+ function groupPagesBySlug(pages, defaultLocale) {
6
+ var _a, _b;
7
+ const groups = {};
8
+ for (const page of pages) {
9
+ const slug = (0, slug_1.normalizeSlug)((0, slug_1.mergeSlug)(page.slug, (_a = page.hub) === null || _a === void 0 ? void 0 : _a.slug));
10
+ const locale = (_b = page.locale) !== null && _b !== void 0 ? _b : defaultLocale;
11
+ if (!groups[slug]) {
12
+ groups[slug] = [];
13
+ }
14
+ groups[slug].push({ slug, locale });
15
+ }
16
+ return groups;
17
+ }
18
+ function buildCanonicalHref(slug, locale, defaultLocale) {
19
+ const path = (0, slug_1.buildPath)(slug, locale, defaultLocale);
20
+ if (path === '/') {
21
+ return '';
22
+ }
23
+ return path.endsWith('/') ? path : `${path}/`;
24
+ }
25
+ function getDefaultHrefLang(pages, defaultLocale) {
26
+ var _a;
27
+ const defaultPage = (_a = pages.find((page) => page.locale === defaultLocale)) !== null && _a !== void 0 ? _a : pages[0];
28
+ return { href: buildCanonicalHref(defaultPage.slug, defaultPage.locale, defaultLocale), hrefLang: 'x-default' };
29
+ }
30
+ function buildHrefLangMap(pages, defaultLocale = 'en') {
31
+ const hrefLangMap = {};
32
+ for (const pageGroup of Object.values(groupPagesBySlug(pages, defaultLocale))) {
33
+ const defaultHreflang = getDefaultHrefLang(pageGroup, defaultLocale);
34
+ for (const page of pageGroup) {
35
+ const hrefLangs = pageGroup.map(({ slug, locale }) => ({
36
+ hrefLang: locale,
37
+ href: buildCanonicalHref(slug, locale, defaultLocale),
38
+ }));
39
+ hrefLangs.push(defaultHreflang);
40
+ const path = (0, slug_1.buildPath)(page.slug, page.locale, defaultLocale);
41
+ hrefLangMap[path] = hrefLangs;
42
+ }
43
+ }
44
+ return hrefLangMap;
45
+ }
@@ -0,0 +1,8 @@
1
+ import type { IPage } from './types';
2
+ export declare function mergeSlug(slug: IPage['slug'], parentSlug: IPage['slug']): string;
3
+ export declare function normalizeSlug(slug?: IPage['slug']): string;
4
+ export declare function normalizeLocale(locale?: IPage['locale']): string;
5
+ export declare function buildPath(slug?: IPage['slug'], locale?: IPage['locale'], defaultLocale?: string): string;
6
+ export declare function isEqualSlug(a?: IPage['slug'], b?: IPage['slug']): boolean;
7
+ export declare function isEmptyPage(title?: IPage['title'], slug?: IPage['slug']): boolean;
8
+ export declare function isDummyPage(slug?: IPage['slug']): boolean;
@@ -1,25 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mergeSlug = mergeSlug;
4
+ exports.normalizeSlug = normalizeSlug;
5
+ exports.normalizeLocale = normalizeLocale;
3
6
  exports.buildPath = buildPath;
4
7
  exports.isEqualSlug = isEqualSlug;
5
8
  exports.isEmptyPage = isEmptyPage;
6
9
  exports.isDummyPage = isDummyPage;
7
10
  const INDEX_PAGE_SLUG = 'index';
8
11
  const DUMMY_PAGE_SLUG = 'dummy';
12
+ function mergeSlug(slug, parentSlug) {
13
+ if (parentSlug) {
14
+ return slug ? `${parentSlug}/${slug}` : parentSlug;
15
+ }
16
+ return slug !== null && slug !== void 0 ? slug : '';
17
+ }
9
18
  function normalizeSlug(slug) {
10
- if (!slug || slug === INDEX_PAGE_SLUG) {
11
- return '';
19
+ if (!slug || slug === INDEX_PAGE_SLUG || slug === '/') {
20
+ return '/';
12
21
  }
13
- return slug.toLowerCase();
22
+ const lowercaseSlug = slug.toLowerCase();
23
+ return lowercaseSlug.startsWith('/') ? lowercaseSlug : `/${lowercaseSlug}`;
14
24
  }
15
25
  function normalizeLocale(locale) {
16
26
  return (locale !== null && locale !== void 0 ? locale : '').toLowerCase();
17
27
  }
18
28
  function buildPath(slug, locale, defaultLocale) {
29
+ const normalizedSlug = normalizeSlug(slug);
19
30
  const normalizedLocale = normalizeLocale(locale);
20
31
  const normalizedDefaultLocale = normalizeLocale(defaultLocale);
21
- const localePrefix = normalizedLocale === normalizedDefaultLocale ? '/' : `/${normalizedLocale}/`;
22
- return `${localePrefix}${normalizeSlug(slug)}`;
32
+ const localePrefix = normalizedLocale === normalizedDefaultLocale ? null : normalizedLocale;
33
+ return localePrefix ? `/${localePrefix}${normalizedSlug}` : normalizedSlug;
23
34
  }
24
35
  function isEqualSlug(a, b) {
25
36
  return normalizeSlug(a) === normalizeSlug(b);
@@ -28,5 +39,5 @@ function isEmptyPage(title, slug) {
28
39
  return !title && !slug;
29
40
  }
30
41
  function isDummyPage(slug) {
31
- return normalizeSlug(slug) === DUMMY_PAGE_SLUG;
42
+ return normalizeSlug(slug) === normalizeSlug(DUMMY_PAGE_SLUG);
32
43
  }
@@ -0,0 +1,21 @@
1
+ type Path = string;
2
+ type NormalizedSlug = string;
3
+ export interface IPage {
4
+ title?: string | null;
5
+ slug?: string | null;
6
+ locale?: string | null;
7
+ hub?: {
8
+ slug?: string | null;
9
+ } | null;
10
+ }
11
+ interface IExistedPage {
12
+ slug: NonNullable<IPage['slug']>;
13
+ locale: NonNullable<IPage['locale']>;
14
+ }
15
+ export type PageGroup = Record<NormalizedSlug, IExistedPage[]>;
16
+ export interface IHrefLang {
17
+ href: string;
18
+ hrefLang: string;
19
+ }
20
+ export type HrefLangMap = Record<Path, IHrefLang[]>;
21
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare const hub = "\n # === PAGE HUB DEFINITION ===\n type Hub {\n name: String!\n slug: String!\n }\n ";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hub = void 0;
4
+ exports.hub = `
5
+ # === PAGE HUB DEFINITION ===
6
+ type Hub {
7
+ name: String!
8
+ slug: String!
9
+ }
10
+ `;
@@ -1 +1 @@
1
- export declare const page = "\n # === STRAPI PAGE DEFINITION ===\n type StrapiPage implements Node {\n id: ID!\n locale: String\n title: String\n slug: String\n seo: Seo\n author: Author\n createdAt: Date @dateformat\n updatedAt: Date @dateformat\n content: [ContentComponent]\n }\n";
1
+ export declare const page = "\n # === STRAPI PAGE DEFINITION ===\n type StrapiPage implements Node {\n id: ID!\n locale: String\n title: String\n slug: String\n seo: Seo\n author: Author\n hub: Hub\n createdAt: Date @dateformat\n updatedAt: Date @dateformat\n content: [ContentComponent]\n }\n";
@@ -10,6 +10,7 @@ exports.page = `
10
10
  slug: String
11
11
  seo: Seo
12
12
  author: Author
13
+ hub: Hub
13
14
  createdAt: Date @dateformat
14
15
  updatedAt: Date @dateformat
15
16
  content: [ContentComponent]
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.typeDefs = void 0;
4
4
  const author_1 = require("./collections/author");
5
+ const hub_1 = require("./collections/hub");
5
6
  const page_1 = require("./collections/page");
6
7
  const partner_1 = require("./collections/partner");
7
8
  const base_1 = require("./components/base");
@@ -11,4 +12,16 @@ const primitives_1 = require("./primitives");
11
12
  const localization_1 = require("./single/localization");
12
13
  const navigation_1 = require("./single/navigation");
13
14
  const site_1 = require("./single/site");
14
- exports.typeDefs = [author_1.author, page_1.page, partner_1.partner, base_1.base, content_1.content, shared_1.shared, primitives_1.primitives, localization_1.localization, navigation_1.navigation, site_1.site].join('\n');
15
+ exports.typeDefs = [
16
+ author_1.author,
17
+ hub_1.hub,
18
+ page_1.page,
19
+ partner_1.partner,
20
+ base_1.base,
21
+ content_1.content,
22
+ shared_1.shared,
23
+ primitives_1.primitives,
24
+ localization_1.localization,
25
+ navigation_1.navigation,
26
+ site_1.site,
27
+ ].join('\n');
@@ -47,6 +47,9 @@ function sourceStrapiContentNode(args, strapiClient, config) {
47
47
  singularName: 'page',
48
48
  queryParams: {
49
49
  populate: {
50
+ hub: {
51
+ populate: '*',
52
+ },
50
53
  seo: {
51
54
  populate: '*',
52
55
  },
@@ -1,4 +0,0 @@
1
- export declare function buildPath(slug?: string | null, locale?: string | null, defaultLocale?: string | null): string;
2
- export declare function isEqualSlug(a?: string | null, b?: string | null): boolean;
3
- export declare function isEmptyPage(title?: string | null, slug?: string | null): boolean;
4
- export declare function isDummyPage(slug?: string | null): boolean;