gatsby-theme-q3 3.1.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -3,58 +3,97 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- # [3.1.0](https://github.com/3merge/q/compare/v3.0.4...v3.1.0) (2022-01-31)
7
-
8
- **Note:** Version bump only for package gatsby-theme-q3
9
-
10
-
11
-
12
-
13
-
14
- ## [3.0.4](https://github.com/3merge/q/compare/v3.0.3...v3.0.4) (2022-01-29)
15
-
16
- **Note:** Version bump only for package gatsby-theme-q3
17
-
18
-
19
-
20
-
21
-
22
- ## [3.0.3](https://github.com/3merge/q/compare/v3.0.2...v3.0.3) (2022-01-29)
6
+ ## [3.2.1](https://github.com/3merge/q/compare/v3.2.0...v3.2.1) (2022-02-09)
23
7
 
24
8
 
25
9
  ### Bug Fixes
26
10
 
27
- * major release bugs ([#372](https://github.com/3merge/q/issues/372)) ([d3e0681](https://github.com/3merge/q/commit/d3e0681a8d9ce61558b3aeaabe94ce8bc326dfa7))
11
+ * misc domain issues ([17cb74b](https://github.com/3merge/q/commit/17cb74b927721f11b5fcd8f8a9a1a28a86867048))
28
12
 
29
13
 
30
14
 
31
15
 
32
16
 
33
- ## [3.0.2](https://github.com/3merge/q/compare/v3.0.1...v3.0.2) (2022-01-28)
34
-
35
- **Note:** Version bump only for package gatsby-theme-q3
17
+ # [3.2.0](https://github.com/3merge/q/compare/v3.1.5...v3.2.0) (2022-02-09)
36
18
 
37
19
 
20
+ ### Features
38
21
 
39
-
40
-
41
- ## [3.0.1](https://github.com/3merge/q/compare/v3.0.0...v3.0.1) (2022-01-28)
42
-
43
- **Note:** Version bump only for package gatsby-theme-q3
44
-
45
-
46
-
47
-
48
-
49
- # [3.0.0](https://github.com/3merge/q/compare/v2.3.13...v3.0.0) (2022-01-28)
50
-
51
- **Note:** Version bump only for package gatsby-theme-q3
22
+ * text locale editor ([#377](https://github.com/3merge/q/issues/377)) ([e827875](https://github.com/3merge/q/commit/e8278757be7505554376c1d1d78d9b8900fdf35e))
52
23
 
53
24
 
54
25
 
55
26
 
56
27
 
57
28
 
29
+ ## [3.1.5](https://github.com/3merge/q/compare/v3.1.4...v3.1.5) (2022-02-01)
30
+
31
+ **Note:** Version bump only for package gatsby-theme-q3
32
+
33
+
34
+
35
+
36
+
37
+ ## [3.1.4](https://github.com/3merge/q/compare/v3.1.3...v3.1.4) (2022-02-01)
38
+
39
+ **Note:** Version bump only for package gatsby-theme-q3
40
+
41
+
42
+
43
+
44
+
45
+ # [3.1.0](https://github.com/3merge/q/compare/v3.0.4...v3.1.0) (2022-01-31)
46
+
47
+ **Note:** Version bump only for package gatsby-theme-q3
48
+
49
+
50
+
51
+
52
+
53
+ ## [3.0.4](https://github.com/3merge/q/compare/v3.0.3...v3.0.4) (2022-01-29)
54
+
55
+ **Note:** Version bump only for package gatsby-theme-q3
56
+
57
+
58
+
59
+
60
+
61
+ ## [3.0.3](https://github.com/3merge/q/compare/v3.0.2...v3.0.3) (2022-01-29)
62
+
63
+
64
+ ### Bug Fixes
65
+
66
+ * major release bugs ([#372](https://github.com/3merge/q/issues/372)) ([d3e0681](https://github.com/3merge/q/commit/d3e0681a8d9ce61558b3aeaabe94ce8bc326dfa7))
67
+
68
+
69
+
70
+
71
+
72
+ ## [3.0.2](https://github.com/3merge/q/compare/v3.0.1...v3.0.2) (2022-01-28)
73
+
74
+ **Note:** Version bump only for package gatsby-theme-q3
75
+
76
+
77
+
78
+
79
+
80
+ ## [3.0.1](https://github.com/3merge/q/compare/v3.0.0...v3.0.1) (2022-01-28)
81
+
82
+ **Note:** Version bump only for package gatsby-theme-q3
83
+
84
+
85
+
86
+
87
+
88
+ # [3.0.0](https://github.com/3merge/q/compare/v2.3.13...v3.0.0) (2022-01-28)
89
+
90
+ **Note:** Version bump only for package gatsby-theme-q3
91
+
92
+
93
+
94
+
95
+
96
+
58
97
  ## [2.3.11](https://github.com/3merge/q/compare/v2.3.10...v2.3.11) (2022-01-18)
59
98
 
60
99
  **Note:** Version bump only for package gatsby-theme-q3
package/gatsby-browser.js CHANGED
@@ -1,4 +1,33 @@
1
+ import axios from 'axios';
2
+ import { last, size } from 'lodash';
3
+ import { getDomain } from 'q3-admin';
4
+ import { browser } from 'q3-ui-helpers';
5
+
1
6
  export {
2
7
  wrapPageElement,
3
8
  wrapRootElement,
4
9
  } from './gatsby-ssr';
10
+
11
+ export const onClientEntry = async () => {
12
+ if (!browser.isBrowserReady()) return;
13
+
14
+ // set api default root
15
+ axios.defaults.baseURL =
16
+ process.env.GATSBY_APP_BASE_URL ||
17
+ 'http://localhost:9000';
18
+
19
+ // set language default
20
+ axios.defaults.headers['Content-Language'] =
21
+ window.localStorage.getItem('q3-locale') || 'en';
22
+
23
+ // set tenant default
24
+ const { host } = window.location;
25
+ const parts = String(host).split('.').reverse();
26
+
27
+ if (size(parts) > 1)
28
+ axios.defaults.headers['X-Session-Tenant'] =
29
+ last(parts);
30
+
31
+ // calls Q3 API
32
+ await getDomain();
33
+ };
package/gatsby-config.js CHANGED
@@ -4,16 +4,7 @@ require('dotenv').config();
4
4
  const genKey = (url) =>
5
5
  String(url).includes('netlify') ? 'disallow' : 'allow';
6
6
 
7
- module.exports = ({
8
- contentfulSpaceID,
9
- contentfulAccessToken,
10
- siteUrl,
11
- title,
12
- brandingColor,
13
- icon,
14
- netlify,
15
- ...options
16
- }) => {
7
+ module.exports = (options) => {
17
8
  const plugins = [
18
9
  {
19
10
  resolve: 'gatsby-theme-q3-mui',
@@ -50,51 +41,20 @@ module.exports = ({
50
41
  },
51
42
  },
52
43
  },
53
- ];
54
-
55
- if (contentfulSpaceID) {
56
- if (!contentfulAccessToken)
57
- throw new Error('Contentful access token missing');
58
-
59
- plugins.push({
60
- resolve: 'gatsby-source-contentful',
61
- options: {
62
- spaceId: contentfulSpaceID,
63
- accessToken: contentfulAccessToken,
64
- },
65
- });
66
- }
67
-
68
- if (netlify)
69
- plugins.push({
44
+ {
70
45
  resolve: 'gatsby-plugin-netlify',
71
46
  options: {
72
47
  generateMatchPathRewrites: true,
73
48
  },
74
- });
75
-
76
- if (title && brandingColor)
77
- plugins.push({
78
- resolve: 'gatsby-plugin-manifest',
79
- options: {
80
- short_name: title,
81
- start_url: '/',
82
- background_color: '#FFF',
83
- theme_color: brandingColor,
84
- display: 'standalone',
85
- name: title,
86
- icon,
87
- },
88
- });
89
-
90
- if (siteUrl)
91
- plugins.push({
49
+ },
50
+ {
92
51
  resolve: 'gatsby-plugin-canonical-urls',
93
52
  options: {
94
53
  stripQueryString: true,
95
- siteUrl,
54
+ siteUrl: process.env.URL,
96
55
  },
97
- });
56
+ },
57
+ ];
98
58
 
99
59
  return {
100
60
  plugins,
package/gatsby-node.js CHANGED
@@ -70,7 +70,6 @@ exports.onCreatePage = async ({ page, actions }) => {
70
70
  createPage({
71
71
  ...page,
72
72
  context: {
73
- contentful_id: 'APP',
74
73
  to: '/app',
75
74
  },
76
75
  });
@@ -13,21 +13,12 @@ var _components = require("q3-admin/lib/components");
13
13
 
14
14
  var _SearchEngine = _interopRequireDefault(require("./SearchEngine"));
15
15
 
16
- var _useLocale = _interopRequireDefault(require("./useLocale"));
17
-
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
17
 
20
- // cannot conditionally call hooks otherwise
21
- const Locale = () => {
22
- (0, _useLocale.default)();
23
- return null;
24
- };
25
-
26
18
  const PageWrapper = ({
27
19
  children,
28
- includeLoader,
29
- includeLocale
30
- }) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_SearchEngine.default, null), includeLoader && /*#__PURE__*/_react.default.createElement(_components.Loader, null), includeLocale && /*#__PURE__*/_react.default.createElement(Locale, null), children);
20
+ includeLoader
21
+ }) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_SearchEngine.default, null), includeLoader && /*#__PURE__*/_react.default.createElement(_components.Loader, null), children);
31
22
 
32
23
  PageWrapper.defaultProps = {
33
24
  children: null,
@@ -3,18 +3,72 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.getStartUrl = exports.generateMetaTitleOptions = exports.generateMetaDescriptionOptions = exports.generateManifest = exports.generateIcons = exports.generateBrand = exports.default = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
+ var _lodash = require("lodash");
11
+
10
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
13
 
12
14
  var _reactHelmet = require("react-helmet");
13
15
 
16
+ var _q3UiHelpers = require("q3-ui-helpers");
17
+
14
18
  var _useSiteMetaData = _interopRequireDefault(require("./useSiteMetaData"));
15
19
 
16
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
21
 
22
+ const withContent = output => content => content && (0, _lodash.isFunction)(output) ? output(content) : [];
23
+
24
+ const getStartUrl = () => _q3UiHelpers.browser.isBrowserReady() ? (0, _lodash.get)(window, 'location.host') : '';
25
+
26
+ exports.getStartUrl = getStartUrl;
27
+ const generateMetaDescriptionOptions = withContent(content => [{
28
+ name: 'description',
29
+ content
30
+ }, {
31
+ property: 'og:description',
32
+ content
33
+ }, {
34
+ name: 'twitter:description',
35
+ content
36
+ }]);
37
+ exports.generateMetaDescriptionOptions = generateMetaDescriptionOptions;
38
+ const generateMetaTitleOptions = withContent(content => [{
39
+ property: 'og:title',
40
+ content
41
+ }, {
42
+ name: 'twitter:title',
43
+ content
44
+ }]);
45
+ exports.generateMetaTitleOptions = generateMetaTitleOptions;
46
+
47
+ const generateBrand = xs => xs ? `%s | ${xs}` : undefined;
48
+
49
+ exports.generateBrand = generateBrand;
50
+
51
+ const generateIcons = (site = {}) => site !== null && site !== void 0 && site.favicon ? [{
52
+ src: site.favicon,
53
+ sizes: '512x512',
54
+ type: 'image/png'
55
+ }] : [];
56
+
57
+ exports.generateIcons = generateIcons;
58
+
59
+ const generateManifest = (site = {}) => ({
60
+ background_color: site.color,
61
+ description: site.description,
62
+ display: 'fullscreen',
63
+ icons: generateIcons(site),
64
+ name: site.title,
65
+ start_url: getStartUrl(),
66
+ short_name: site.brand,
67
+ theme_color: site.color
68
+ });
69
+
70
+ exports.generateManifest = generateManifest;
71
+
18
72
  const SEO = ({
19
73
  description,
20
74
  lang,
@@ -23,35 +77,28 @@ const SEO = ({
23
77
  }) => {
24
78
  const site = (0, _useSiteMetaData.default)();
25
79
  const metaDescription = description || site.description;
80
+ const metaTitle = title || site.title;
81
+ const manifestData = generateManifest(site);
26
82
  return /*#__PURE__*/_react.default.createElement(_reactHelmet.Helmet, {
27
83
  htmlAttributes: {
28
84
  lang
29
85
  },
30
- title: title || site.title,
31
- titleTemplate: `%s | ${site.brand}`,
32
- meta: [{
33
- name: 'description',
34
- content: metaDescription
35
- }, {
36
- property: 'og:title',
37
- content: title
38
- }, {
39
- property: 'og:description',
40
- content: metaDescription
41
- }, {
86
+ title: metaTitle,
87
+ titleTemplate: generateBrand(site.brand),
88
+ meta: [...generateMetaTitleOptions(metaTitle), ...generateMetaDescriptionOptions(metaDescription), {
42
89
  property: 'og:type',
43
90
  content: 'website'
44
91
  }, {
45
92
  name: 'twitter:card',
46
93
  content: 'summary'
47
- }, {
48
- name: 'twitter:title',
49
- content: title
50
- }, {
51
- name: 'twitter:description',
52
- content: metaDescription
53
94
  }].concat(meta)
54
- });
95
+ }, (0, _lodash.isObject)(manifestData) ? /*#__PURE__*/_react.default.createElement("link", {
96
+ rel: "manifest",
97
+ href: `data:application/manifest+json,${encodeURIComponent(JSON.stringify(manifestData))}`
98
+ }) : null, /*#__PURE__*/_react.default.createElement("link", {
99
+ rel: "icon",
100
+ href: site.favicon
101
+ }));
55
102
  };
56
103
 
57
104
  SEO.defaultProps = {
@@ -7,41 +7,19 @@ exports.default = void 0;
7
7
 
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
 
10
- var _axios = _interopRequireDefault(require("axios"));
11
-
12
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
11
 
14
12
  var _q3UiPermissions = _interopRequireDefault(require("q3-ui-permissions"));
15
13
 
16
- var _LocaleBundles = _interopRequireDefault(require("./LocaleBundles"));
17
-
18
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
15
 
20
16
  /* eslint-disable import/no-extraneous-dependencies */
21
- const setBaseUrlForRest = (baseURL = process.env.GATSBY_APP_BASE_URL || 'http://localhost:9000') => {
22
- _axios.default.defaults.baseURL = baseURL;
23
- return _axios.default.defaults;
24
- };
25
-
26
17
  const Wrapper = ({
27
- baseURL,
28
- children,
29
- locale
30
- }) => {
31
- setBaseUrlForRest(baseURL);
32
- return /*#__PURE__*/_react.default.createElement(_LocaleBundles.default, {
33
- locale: locale
34
- }, /*#__PURE__*/_react.default.createElement(_q3UiPermissions.default, null, children));
35
- };
18
+ children
19
+ }) => /*#__PURE__*/_react.default.createElement(_q3UiPermissions.default, null, children);
36
20
 
37
- Wrapper.defaultProps = {
38
- baseURL: undefined
39
- };
40
21
  Wrapper.propTypes = {
41
- baseURL: _propTypes.default.string,
42
- children: _propTypes.default.node.isRequired,
43
- // eslint-disable-next-line
44
- locale: _propTypes.default.object.isRequired
22
+ children: _propTypes.default.node.isRequired
45
23
  };
46
24
  var _default = Wrapper;
47
25
  exports.default = _default;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ var _SearchEngine = require("../SearchEngine");
4
+
5
+ jest.mock('q3-ui-locale', () => ({
6
+ browser: {
7
+ isBrowserReady: jest.fn()
8
+ }
9
+ }));
10
+ const host = 'https://google.ca';
11
+ beforeEach(() => {
12
+ Object.defineProperty(window, 'location', {
13
+ value: {
14
+ host
15
+ }
16
+ });
17
+ });
18
+ describe('SearchEngine', () => {
19
+ it('should not render descriptions without content', () => {
20
+ expect((0, _SearchEngine.generateMetaDescriptionOptions)().length).toBe(0);
21
+ });
22
+ it('should render descriptions with content', () => {
23
+ expect((0, _SearchEngine.generateMetaDescriptionOptions)('foo').length).toBeGreaterThanOrEqual(1);
24
+ });
25
+ it('should return host', () => {
26
+ expect((0, _SearchEngine.getStartUrl)()).toMatch(host);
27
+ });
28
+ it('should render favicon', () => {
29
+ expect((0, _SearchEngine.generateIcons)({
30
+ favicon: host
31
+ })).toHaveLength(1);
32
+ });
33
+ it('should not render favicon', () => {
34
+ expect((0, _SearchEngine.generateIcons)({
35
+ favicon: undefined
36
+ })).toHaveLength(0);
37
+ });
38
+ it('should include template literals', () => {
39
+ expect((0, _SearchEngine.generateBrand)('3merge')).toMatch('%s | 3merge');
40
+ });
41
+ });
@@ -9,19 +9,20 @@ var _lodash = require("lodash");
9
9
 
10
10
  var _gatsby = require("gatsby");
11
11
 
12
- var _default = () => (0, _lodash.get)((0, _gatsby.useStaticQuery)((0, _gatsby.graphql)`
13
- query {
14
- site {
15
- siteMetadata {
16
- appDirectory
17
- brand
18
- description
19
- favicon
20
- logo
21
- title
12
+ var _useRunTime = _interopRequireDefault(require("gatsby-theme-q3-mui/src/components/useRunTime"));
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ var _default = () => (0, _lodash.merge)((0, _lodash.get)((0, _gatsby.useStaticQuery)((0, _gatsby.graphql)`
17
+ query {
18
+ site {
19
+ siteMetadata {
20
+ appDirectory
21
+ description
22
+ title
23
+ }
22
24
  }
23
25
  }
24
- }
25
- `), 'site.siteMetadata', {});
26
+ `), 'site.siteMetadata', {}), (0, _useRunTime.default)());
26
27
 
27
28
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-theme-q3",
3
- "version": "3.1.0",
3
+ "version": "3.2.1",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "peerDependencies": {
@@ -23,24 +23,24 @@
23
23
  "gatsby-image": "^3.11.0",
24
24
  "gatsby-plugin-canonical-urls": "^4.2.0",
25
25
  "gatsby-plugin-force-trailing-slashes": "^1.0.5",
26
- "gatsby-plugin-manifest": "^4.2.0",
27
26
  "gatsby-plugin-material-ui": "^3.0.1",
28
27
  "gatsby-plugin-netlify": "^3.14.0",
29
28
  "gatsby-plugin-robots-txt": "^1.6.14",
30
29
  "gatsby-plugin-sharp": "^4.2.0",
31
30
  "gatsby-plugin-sitemap": "^5.2.0",
32
- "gatsby-source-contentful": "^7.0.0",
33
- "gatsby-theme-q3-mui": "^3.1.0",
31
+ "gatsby-theme-q3-mui": "^3.2.1",
34
32
  "gatsby-transformer-sharp": "^4.2.0",
35
33
  "lodash": "^4.17.20",
36
34
  "process": "^0.11.10",
37
35
  "prop-types": "^15.7.2",
38
- "q3-ui-locale": "^3.1.0",
36
+ "q3-ui-helpers": "^3.2.0",
37
+ "q3-ui-locale": "^3.2.1",
39
38
  "query-string": "^7.0.1",
39
+ "react-helmet": "^6.1.0",
40
40
  "react-share": "^4.3.1",
41
41
  "slugify": "^1.6.3",
42
42
  "transform-loader": "^0.2.4",
43
43
  "yarn": "^1.22.17"
44
44
  },
45
- "gitHead": "346448a8fd596cf2453ed9dcb48fb6dc4f9b8450"
45
+ "gitHead": "b9ee55eb96e7d61f86f9d5d091d8a9d770c720cc"
46
46
  }
@@ -2,23 +2,11 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Loader } from 'q3-admin/lib/components';
4
4
  import SearchEngine from './SearchEngine';
5
- import useLocale from './useLocale';
6
5
 
7
- // cannot conditionally call hooks otherwise
8
- const Locale = () => {
9
- useLocale();
10
- return null;
11
- };
12
-
13
- const PageWrapper = ({
14
- children,
15
- includeLoader,
16
- includeLocale,
17
- }) => (
6
+ const PageWrapper = ({ children, includeLoader }) => (
18
7
  <>
19
8
  <SearchEngine />
20
9
  {includeLoader && <Loader />}
21
- {includeLocale && <Locale />}
22
10
  {children}
23
11
  </>
24
12
  );