gatsby-theme-q3 3.2.0 → 3.2.4
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +38 -0
- package/gatsby-browser.js +5 -0
- package/gatsby-config.js +7 -18
- package/gatsby-node.js +0 -1
- package/lib/components/FormBoxContent.js +2 -1
- package/lib/components/PageWrapper.js +1 -2
- package/lib/components/PublicTemplate.js +130 -6
- package/lib/components/SearchEngine.js +7 -10
- package/lib/components/Wrapper.js +2 -19
- package/lib/components/withPublicTemplate.js +17 -0
- package/lib/components/withSuccessOp.js +1 -1
- package/lib/pages/login.js +7 -4
- package/lib/pages/password-change.js +4 -3
- package/lib/pages/password-reset.js +4 -3
- package/lib/pages/reverify.js +5 -2
- package/lib/pages/verify.js +5 -3
- package/package.json +4 -4
- package/src/components/FormBoxContent.jsx +1 -1
- package/src/components/PageWrapper.jsx +1 -5
- package/src/components/PublicTemplate.jsx +134 -5
- package/src/components/SearchEngine.jsx +10 -14
- package/src/components/Wrapper.jsx +3 -21
- package/src/components/withPublicTemplate.jsx +11 -0
- package/src/components/withSuccessOp.jsx +1 -1
- package/src/pages/login.jsx +55 -43
- package/src/pages/password-change.jsx +5 -3
- package/src/pages/password-reset.jsx +5 -3
- package/src/pages/reverify.jsx +4 -2
- package/src/pages/verify.jsx +9 -12
- package/__tests__/config.int.test.js +0 -62
- package/helpers/__tests__/loadContent.unit.test.js +0 -13
- package/helpers/__tests__/pagination.unit.test.js +0 -139
- package/helpers/__tests__/slug.unit.test.js +0 -21
- package/helpers/archive.js +0 -42
- package/helpers/index.js +0 -19
- package/helpers/loadContent.js +0 -45
- package/helpers/loadTheme.js +0 -10
- package/helpers/pagination.js +0 -109
- package/helpers/setup.js +0 -60
- package/helpers/slug.js +0 -31
- package/helpers/slugType.js +0 -24
@@ -1,21 +0,0 @@
|
|
1
|
-
const slug = require('../slug');
|
2
|
-
|
3
|
-
describe('slug', () => {
|
4
|
-
it('should combine use slug attribute', () => {
|
5
|
-
expect(
|
6
|
-
slug({ slug: 'already-formatted-as-slug' }),
|
7
|
-
).toMatch('/already-formatted-as-slug');
|
8
|
-
});
|
9
|
-
|
10
|
-
it('should combine use title attribute', () => {
|
11
|
-
expect(
|
12
|
-
slug({ title: 'This is a post' }, 'foos'),
|
13
|
-
).toMatch('/foos/this-is-a-post');
|
14
|
-
});
|
15
|
-
|
16
|
-
it('should combine use name attribute', () => {
|
17
|
-
expect(slug({ name: "Post's name" }, '/foos')).toMatch(
|
18
|
-
'/foos/posts-name',
|
19
|
-
);
|
20
|
-
});
|
21
|
-
});
|
package/helpers/archive.js
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
const { get } = require('lodash');
|
2
|
-
const { resolve } = require('path');
|
3
|
-
const {
|
4
|
-
appendSiblingsToContext,
|
5
|
-
paginateArchiveContext,
|
6
|
-
} = require('./pagination');
|
7
|
-
|
8
|
-
module.exports = ({
|
9
|
-
archiveComponentRelativePath,
|
10
|
-
createPage,
|
11
|
-
detailComponentRelativePath,
|
12
|
-
nodesKeyName,
|
13
|
-
slug,
|
14
|
-
}) => async ({ data, errors }) => {
|
15
|
-
if (errors) throw errors;
|
16
|
-
const { nodes = [] } = get(data, nodesKeyName, {
|
17
|
-
nodes: [],
|
18
|
-
});
|
19
|
-
|
20
|
-
const archives = appendSiblingsToContext(nodes).map(
|
21
|
-
(context) =>
|
22
|
-
createPage({
|
23
|
-
path:
|
24
|
-
// see slugType for more details on this field
|
25
|
-
context.to || `/${slug}/${context.contentful_id}`,
|
26
|
-
component: resolve(detailComponentRelativePath),
|
27
|
-
context,
|
28
|
-
}),
|
29
|
-
);
|
30
|
-
|
31
|
-
const entries = paginateArchiveContext(nodes, slug).map(
|
32
|
-
({ path, ...context }) =>
|
33
|
-
createPage({
|
34
|
-
component: resolve(archiveComponentRelativePath),
|
35
|
-
path,
|
36
|
-
context,
|
37
|
-
}),
|
38
|
-
);
|
39
|
-
|
40
|
-
await Promise.all(archives);
|
41
|
-
await Promise.all(entries);
|
42
|
-
};
|
package/helpers/index.js
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
const ArchiveBuilder = require('./archive');
|
2
|
-
const loadContent = require('./loadContent');
|
3
|
-
const {
|
4
|
-
appendSiblingsToContext,
|
5
|
-
paginateArchiveContext,
|
6
|
-
} = require('./pagination');
|
7
|
-
const slug = require('./slug');
|
8
|
-
const slugType = require('./slugType');
|
9
|
-
const setup = require('./setup');
|
10
|
-
|
11
|
-
module.exports = {
|
12
|
-
ArchiveBuilder,
|
13
|
-
loadContent,
|
14
|
-
appendSiblingsToContext,
|
15
|
-
paginateArchiveContext,
|
16
|
-
setup,
|
17
|
-
slug,
|
18
|
-
slugType,
|
19
|
-
};
|
package/helpers/loadContent.js
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
const fs = require('fs');
|
2
|
-
const path = require('path');
|
3
|
-
|
4
|
-
const readJsonFile = (dir, filename) => {
|
5
|
-
try {
|
6
|
-
const file = path.resolve(dir, filename);
|
7
|
-
const buffer = fs.readFileSync(file);
|
8
|
-
return JSON.parse(buffer);
|
9
|
-
} catch (e) {
|
10
|
-
return {};
|
11
|
-
}
|
12
|
-
};
|
13
|
-
|
14
|
-
const reduceFileSystem = (name, next) =>
|
15
|
-
fs
|
16
|
-
.readdirSync(name, { withFileTypes: true })
|
17
|
-
.reduce(next, {});
|
18
|
-
|
19
|
-
const getJsonFileNameFromDirent = ({ name }) =>
|
20
|
-
path.basename(name, '.json');
|
21
|
-
|
22
|
-
const readFilePathFromDirent = ({ name }, root, next) =>
|
23
|
-
next(path.join(root, name));
|
24
|
-
|
25
|
-
const recurseFileSystem = (pathName) =>
|
26
|
-
reduceFileSystem(pathName, (curr, dirent) =>
|
27
|
-
Object.assign(curr, {
|
28
|
-
[getJsonFileNameFromDirent(
|
29
|
-
dirent,
|
30
|
-
)]: dirent.isDirectory()
|
31
|
-
? readFilePathFromDirent(
|
32
|
-
dirent,
|
33
|
-
pathName,
|
34
|
-
recurseFileSystem,
|
35
|
-
)
|
36
|
-
: readJsonFile(pathName, dirent.name),
|
37
|
-
}),
|
38
|
-
);
|
39
|
-
|
40
|
-
recurseFileSystem.readJsonFile = readJsonFile;
|
41
|
-
recurseFileSystem.reduceFileSystem = reduceFileSystem;
|
42
|
-
recurseFileSystem.getJsonFileNameFromDirent = getJsonFileNameFromDirent;
|
43
|
-
recurseFileSystem.readFilePathFromDirent = readFilePathFromDirent;
|
44
|
-
|
45
|
-
module.exports = recurseFileSystem;
|
package/helpers/loadTheme.js
DELETED
package/helpers/pagination.js
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
const { get } = require('lodash');
|
2
|
-
|
3
|
-
const getId = (v) => get(v, 'contentful_id');
|
4
|
-
|
5
|
-
const genCursor = (a = [], i = 0) => ({
|
6
|
-
isFirst: i === 0,
|
7
|
-
isLast: i === a.length - 1,
|
8
|
-
next: a[i + 1],
|
9
|
-
prev: a[i - 1],
|
10
|
-
first: a[0],
|
11
|
-
last: a[a.length - 1],
|
12
|
-
});
|
13
|
-
|
14
|
-
const joinArchiveUrlWithPageNumber = (url, page) =>
|
15
|
-
`${url}/${page}`;
|
16
|
-
|
17
|
-
const getPreviousArchiveUrl = (archiveUrl, page) => {
|
18
|
-
if (page === 2) return archiveUrl;
|
19
|
-
if (page !== 1)
|
20
|
-
return joinArchiveUrlWithPageNumber(
|
21
|
-
archiveUrl,
|
22
|
-
page - 1,
|
23
|
-
);
|
24
|
-
|
25
|
-
return null;
|
26
|
-
};
|
27
|
-
|
28
|
-
const getNextArchiveUrl = (
|
29
|
-
archiveUrl,
|
30
|
-
page,
|
31
|
-
totalNumberOfPages,
|
32
|
-
) => {
|
33
|
-
if (page < totalNumberOfPages)
|
34
|
-
return joinArchiveUrlWithPageNumber(
|
35
|
-
archiveUrl,
|
36
|
-
page + 1,
|
37
|
-
);
|
38
|
-
|
39
|
-
return null;
|
40
|
-
};
|
41
|
-
|
42
|
-
const getCurrentArchiveUrl = (archiveUrl, page) =>
|
43
|
-
page < 2
|
44
|
-
? archiveUrl
|
45
|
-
: joinArchiveUrlWithPageNumber(archiveUrl, page);
|
46
|
-
|
47
|
-
const getNumberOfPages = (
|
48
|
-
entries = [],
|
49
|
-
postsPerPage = 15,
|
50
|
-
) => {
|
51
|
-
const len = Array.isArray(entries) ? entries.length : 0;
|
52
|
-
return Math.ceil(len / postsPerPage);
|
53
|
-
};
|
54
|
-
|
55
|
-
const appendSiblingsToContext = (entries) =>
|
56
|
-
entries.map((node, i) => {
|
57
|
-
const cursor = genCursor(entries, i);
|
58
|
-
const prev = getId(
|
59
|
-
cursor.isFirst ? cursor.last : cursor.prev,
|
60
|
-
);
|
61
|
-
|
62
|
-
const next = getId(
|
63
|
-
cursor.isLast ? cursor.first : cursor.next,
|
64
|
-
);
|
65
|
-
|
66
|
-
return {
|
67
|
-
...node,
|
68
|
-
prev,
|
69
|
-
next,
|
70
|
-
};
|
71
|
-
});
|
72
|
-
|
73
|
-
const paginateArchiveContext = (entries = [], pathName) => {
|
74
|
-
const postsPerPage = 15;
|
75
|
-
const numPages = getNumberOfPages(entries, postsPerPage);
|
76
|
-
const output = [];
|
77
|
-
|
78
|
-
for (let i = 0; i < numPages; i += 1) {
|
79
|
-
const page = i + 1; // always offset for pretty URLs
|
80
|
-
const path = getCurrentArchiveUrl(pathName, page);
|
81
|
-
const prev = getPreviousArchiveUrl(pathName, page);
|
82
|
-
const next = getNextArchiveUrl(
|
83
|
-
pathName,
|
84
|
-
page,
|
85
|
-
numPages,
|
86
|
-
);
|
87
|
-
|
88
|
-
output.push({
|
89
|
-
limit: postsPerPage,
|
90
|
-
skip: i * postsPerPage,
|
91
|
-
total: numPages,
|
92
|
-
pageNum: i,
|
93
|
-
path,
|
94
|
-
next,
|
95
|
-
prev,
|
96
|
-
});
|
97
|
-
}
|
98
|
-
|
99
|
-
return output;
|
100
|
-
};
|
101
|
-
|
102
|
-
module.exports = {
|
103
|
-
appendSiblingsToContext,
|
104
|
-
genCursor,
|
105
|
-
getNextArchiveUrl,
|
106
|
-
getNumberOfPages,
|
107
|
-
getPreviousArchiveUrl,
|
108
|
-
paginateArchiveContext,
|
109
|
-
};
|
package/helpers/setup.js
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
const path = require('path');
|
2
|
-
const fs = require('fs');
|
3
|
-
const { compact, get } = require('lodash');
|
4
|
-
const loadContent = require('./loadContent');
|
5
|
-
const loadTheme = require('./loadTheme');
|
6
|
-
|
7
|
-
const getFile =
|
8
|
-
(directory) =>
|
9
|
-
(possibleFileNames = []) =>
|
10
|
-
possibleFileNames.reduce((acc, curr) => {
|
11
|
-
if (acc) return acc;
|
12
|
-
const filename = path.resolve(directory, curr);
|
13
|
-
return fs.existsSync(filename) ? filename : undefined;
|
14
|
-
}, undefined);
|
15
|
-
|
16
|
-
module.exports = (
|
17
|
-
siteMetadata,
|
18
|
-
plugins = [],
|
19
|
-
workingDirection = process.cwd(),
|
20
|
-
) => {
|
21
|
-
const f = getFile(workingDirection);
|
22
|
-
|
23
|
-
const locale = loadContent(f(['locale', 'lang']));
|
24
|
-
const theme = loadTheme(
|
25
|
-
f(['theme.js', 'gatsby-theme.js', 'mui.js']),
|
26
|
-
);
|
27
|
-
|
28
|
-
return {
|
29
|
-
siteMetadata: {
|
30
|
-
appDirectory: '/app',
|
31
|
-
author: '3merge',
|
32
|
-
description: '',
|
33
|
-
siteUrl: 'https://3merge.ca/',
|
34
|
-
...siteMetadata,
|
35
|
-
},
|
36
|
-
plugins: compact(
|
37
|
-
[
|
38
|
-
{
|
39
|
-
resolve: 'gatsby-theme-q3',
|
40
|
-
options: {
|
41
|
-
icon: f([
|
42
|
-
'static/favicon.png',
|
43
|
-
'static/favicon.jpg',
|
44
|
-
]),
|
45
|
-
|
46
|
-
brandingColor: get(
|
47
|
-
theme,
|
48
|
-
'palette.primary.main',
|
49
|
-
'#000',
|
50
|
-
),
|
51
|
-
|
52
|
-
locale,
|
53
|
-
theme,
|
54
|
-
...siteMetadata,
|
55
|
-
},
|
56
|
-
},
|
57
|
-
].concat(plugins),
|
58
|
-
),
|
59
|
-
};
|
60
|
-
};
|
package/helpers/slug.js
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
const slugify = require('slugify');
|
2
|
-
|
3
|
-
const getSlug = (target) => {
|
4
|
-
const keys = ['slug', 'title', 'name', 'contentful_id'];
|
5
|
-
|
6
|
-
let slug;
|
7
|
-
let i = 0;
|
8
|
-
|
9
|
-
do {
|
10
|
-
const v = target[keys[i]];
|
11
|
-
if (v)
|
12
|
-
slug = slugify(v, {
|
13
|
-
replacement: '-',
|
14
|
-
remove: undefined,
|
15
|
-
lower: true,
|
16
|
-
strict: true,
|
17
|
-
});
|
18
|
-
|
19
|
-
i += 1;
|
20
|
-
} while (!slug);
|
21
|
-
|
22
|
-
return slug;
|
23
|
-
};
|
24
|
-
|
25
|
-
const getDirectoryPath = (v) => {
|
26
|
-
if (typeof v !== 'string') return '/';
|
27
|
-
return v.startsWith('/') ? v : `/${v}`;
|
28
|
-
};
|
29
|
-
|
30
|
-
module.exports = (node = {}, basepath = '/') =>
|
31
|
-
[getDirectoryPath(basepath), getSlug(node)].join('/');
|
package/helpers/slugType.js
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
const slug = require('./slug');
|
2
|
-
|
3
|
-
module.exports = (
|
4
|
-
dir,
|
5
|
-
resourceName,
|
6
|
-
{ createFieldExtension, createTypes },
|
7
|
-
) => {
|
8
|
-
// mirrors reach router prop
|
9
|
-
// an unlikely name otherwise
|
10
|
-
const resolverKey = 'to';
|
11
|
-
|
12
|
-
createFieldExtension({
|
13
|
-
name: resolverKey,
|
14
|
-
extend: () => ({
|
15
|
-
resolve: (source) => slug(source, dir),
|
16
|
-
}),
|
17
|
-
});
|
18
|
-
|
19
|
-
createTypes(`
|
20
|
-
type ${resourceName} implements Node {
|
21
|
-
${resolverKey}: String @${resolverKey}
|
22
|
-
}
|
23
|
-
`);
|
24
|
-
};
|