@tryghost/algolia 0.3.0 → 0.3.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/README.md +1 -1
- package/bin/cli.js +16 -6
- package/lib/fetch-posts.js +3 -3
- package/lib/utils.js +9 -3
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ If a long `--skip` filter causes a `414 Request-URI Too Large` response, put the
|
|
|
58
58
|
|
|
59
59
|
## Development
|
|
60
60
|
|
|
61
|
-
Install dependencies from the repository root with `pnpm install`. From the root, run this package's tests and
|
|
61
|
+
Install dependencies from the repository root with `pnpm install`. From the root, run this package's tests and lint checks with:
|
|
62
62
|
|
|
63
63
|
```sh
|
|
64
64
|
pnpm --filter @tryghost/algolia test
|
package/bin/cli.js
CHANGED
|
@@ -15,7 +15,7 @@ prettyCLI.command({
|
|
|
15
15
|
flags: 'index <pathToConfig>',
|
|
16
16
|
desc: 'Run a batch index of all Ghost posts to Algolia',
|
|
17
17
|
paramsDesc: ['Path to a valid config JSON file'],
|
|
18
|
-
setup:
|
|
18
|
+
setup: sywac => {
|
|
19
19
|
sywac.boolean('-V --verbose', {
|
|
20
20
|
defaultValue: false,
|
|
21
21
|
desc: 'Show verbose output'
|
|
@@ -35,7 +35,10 @@ prettyCLI.command({
|
|
|
35
35
|
desc: 'Exclude post slugs from config JSON file'
|
|
36
36
|
});
|
|
37
37
|
sywac.check((argv, context) => {
|
|
38
|
-
if (
|
|
38
|
+
if (
|
|
39
|
+
argv.limit !== undefined &&
|
|
40
|
+
(!Number.isInteger(argv.limit) || argv.limit < 1 || argv.limit > 100)
|
|
41
|
+
) {
|
|
39
42
|
context.cliMessage('--limit must be an integer from 1 to 100.');
|
|
40
43
|
}
|
|
41
44
|
|
|
@@ -48,7 +51,7 @@ prettyCLI.command({
|
|
|
48
51
|
}
|
|
49
52
|
});
|
|
50
53
|
},
|
|
51
|
-
run: async
|
|
54
|
+
run: async argv => {
|
|
52
55
|
const mainTimer = Date.now();
|
|
53
56
|
let context = {errors: [], posts: []};
|
|
54
57
|
|
|
@@ -87,7 +90,9 @@ prettyCLI.command({
|
|
|
87
90
|
fetchOptions.limit = argv.limit;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
ui.log.info(
|
|
93
|
+
ui.log.info(
|
|
94
|
+
`Fetching ${argv.limit === undefined ? 'all' : argv.limit} posts from Ghost...`
|
|
95
|
+
);
|
|
91
96
|
|
|
92
97
|
if (argv.page !== undefined) {
|
|
93
98
|
ui.log.info(`...from page #${argv.page}.`);
|
|
@@ -114,7 +119,10 @@ prettyCLI.command({
|
|
|
114
119
|
ui.log.info(`Skipping the ${ignoreSlugsCount} slugs in ${argv.pathToConfig}`);
|
|
115
120
|
}
|
|
116
121
|
|
|
117
|
-
context.posts = transforms.transformToAlgoliaObject(
|
|
122
|
+
context.posts = transforms.transformToAlgoliaObject(
|
|
123
|
+
context.posts,
|
|
124
|
+
context.ignore_slugs
|
|
125
|
+
);
|
|
118
126
|
|
|
119
127
|
context.fragments = context.posts.reduce(transforms.fragmentTransformer, []);
|
|
120
128
|
|
|
@@ -146,7 +154,9 @@ prettyCLI.command({
|
|
|
146
154
|
|
|
147
155
|
await index.save(context.fragments);
|
|
148
156
|
|
|
149
|
-
ui.log.ok(
|
|
157
|
+
ui.log.ok(
|
|
158
|
+
`${context.fragments.length} Fragments successfully saved to Algolia index in ${Date.now() - timer}ms.`
|
|
159
|
+
);
|
|
150
160
|
} catch (error) {
|
|
151
161
|
context.errors.push(error);
|
|
152
162
|
return ui.log.error('Error saving fragments', context.errors);
|
package/lib/fetch-posts.js
CHANGED
|
@@ -2,12 +2,12 @@ const DEFAULT_PAGE_SIZE = 100;
|
|
|
2
2
|
const PAGE_DELAY_MS = 100;
|
|
3
3
|
|
|
4
4
|
const waitBetweenPages = () => {
|
|
5
|
-
return new Promise(
|
|
5
|
+
return new Promise(resolve => {
|
|
6
6
|
setTimeout(resolve, PAGE_DELAY_MS);
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
const getNextPage =
|
|
10
|
+
const getNextPage = posts => {
|
|
11
11
|
if (!posts.meta || !posts.meta.pagination || typeof posts.meta.pagination !== 'object') {
|
|
12
12
|
throw TypeError('Ghost returned posts without pagination metadata.');
|
|
13
13
|
}
|
|
@@ -21,7 +21,7 @@ const getNextPage = (posts) => {
|
|
|
21
21
|
return nextPage;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const validatePosts =
|
|
24
|
+
const validatePosts = posts => {
|
|
25
25
|
if (!Array.isArray(posts)) {
|
|
26
26
|
throw TypeError('Ghost returned posts in an invalid format.');
|
|
27
27
|
}
|
package/lib/utils.js
CHANGED
|
@@ -2,7 +2,9 @@ const errors = require('@tryghost/errors');
|
|
|
2
2
|
|
|
3
3
|
module.exports.verifyConfig = ({ghost, algolia}) => {
|
|
4
4
|
if (!ghost || !algolia) {
|
|
5
|
-
throw new errors.BadRequestError({
|
|
5
|
+
throw new errors.BadRequestError({
|
|
6
|
+
message: 'Config has the wrong format. Check `example.json` for reference.'
|
|
7
|
+
});
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
// Check for all Ghost keys
|
|
@@ -12,11 +14,15 @@ module.exports.verifyConfig = ({ghost, algolia}) => {
|
|
|
12
14
|
|
|
13
15
|
// Check for all Ghost keys
|
|
14
16
|
if (!algolia.apiKey || !algolia.appId || !algolia.index) {
|
|
15
|
-
throw new errors.BadRequestError({
|
|
17
|
+
throw new errors.BadRequestError({
|
|
18
|
+
message: 'Algolia index, appId or apiKey are missing.'
|
|
19
|
+
});
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
if (algolia.indexSettings && Object.keys(algolia.indexSettings) < 1) {
|
|
19
|
-
throw new errors.BadRequestError({
|
|
23
|
+
throw new errors.BadRequestError({
|
|
24
|
+
message: 'Algolia indexSettings are empty. Please remove or provide own settings.'
|
|
25
|
+
});
|
|
20
26
|
}
|
|
21
27
|
|
|
22
28
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/algolia",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TryGhost/algolia.git",
|
|
@@ -24,17 +24,17 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@tryghost/content-api": "1.12.10",
|
|
27
|
-
"@tryghost/errors": "
|
|
28
|
-
"@tryghost/pretty-cli": "
|
|
27
|
+
"@tryghost/errors": "3.3.7",
|
|
28
|
+
"@tryghost/pretty-cli": "3.3.7",
|
|
29
29
|
"fs-extra": "11.4.0",
|
|
30
|
-
"@tryghost/algolia-fragmenter": "^0.2.
|
|
31
|
-
"@tryghost/algolia-indexer": "^0.3.
|
|
30
|
+
"@tryghost/algolia-fragmenter": "^0.2.9",
|
|
31
|
+
"@tryghost/algolia-indexer": "^0.3.3"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"dev": "algolia",
|
|
35
35
|
"algolia": "algolia",
|
|
36
36
|
"test": "NODE_ENV=testing vitest run --root .",
|
|
37
|
-
"lint": "
|
|
37
|
+
"lint": "oxlint --quiet . && oxfmt --check .",
|
|
38
38
|
"posttest": "pnpm lint"
|
|
39
39
|
}
|
|
40
40
|
}
|