@tryghost/algolia-fragmenter 0.2.7 → 0.2.9
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/LICENSE +1 -1
- package/README.md +23 -20
- package/lib/transformer.js +4 -8
- package/package.json +16 -15
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
1
|
# Algolia Fragmenter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@tryghost/algolia-fragmenter` converts Ghost posts into Algolia records and breaks long HTML into heading-based fragments.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```sh
|
|
8
|
+
npm install @tryghost/algolia-fragmenter
|
|
9
|
+
```
|
|
8
10
|
|
|
9
11
|
or
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add @tryghost/algolia-fragmenter
|
|
15
|
+
```
|
|
13
16
|
|
|
14
17
|
## Usage
|
|
15
18
|
|
|
19
|
+
Convert Ghost Content API posts, then reduce the resulting records into fragments:
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
This is a mono repository, managed with [lerna](https://lernajs.io/).
|
|
20
|
-
|
|
21
|
-
Follow the instructions for the top-level repo.
|
|
22
|
-
1. `git clone` this repo & `cd` into it as usual
|
|
23
|
-
2. Run `yarn` to install top-level dependencies.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## Run
|
|
21
|
+
```js
|
|
22
|
+
const transforms = require('@tryghost/algolia-fragmenter');
|
|
27
23
|
|
|
28
|
-
|
|
24
|
+
const records = transforms.transformToAlgoliaObject(posts);
|
|
25
|
+
const fragments = records.reduce(transforms.fragmentTransformer, []);
|
|
26
|
+
```
|
|
29
27
|
|
|
28
|
+
`transformToAlgoliaObject` accepts an optional array of post slugs to exclude as its second argument. `fragmentTransformer` is designed to be passed directly to `Array#reduce`.
|
|
30
29
|
|
|
31
|
-
##
|
|
30
|
+
## Development
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
- `yarn test` run lint and tests
|
|
32
|
+
Install dependencies from the repository root with `pnpm install`. From the root, run this package's tests and lint checks with:
|
|
35
33
|
|
|
34
|
+
```sh
|
|
35
|
+
pnpm --filter @tryghost/algolia-fragmenter test
|
|
36
|
+
```
|
|
36
37
|
|
|
38
|
+
Run the full monorepo suite with `pnpm test`.
|
|
37
39
|
|
|
40
|
+
---
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
## Copyright & License
|
|
40
43
|
|
|
41
|
-
Copyright (c) 2013-
|
|
44
|
+
Copyright (c) 2013-2026 Ghost Foundation - Released under the [MIT license](LICENSE). Ghost and the Ghost Logo are trademarks of Ghost Foundation Ltd. Please see our [trademark policy](https://ghost.org/trademark/) for info on acceptable usage.
|
package/lib/transformer.js
CHANGED
|
@@ -56,12 +56,8 @@ module.exports.fragmentTransformer = (recordAccumulator, node) => {
|
|
|
56
56
|
|
|
57
57
|
// TODO: switch this on in verbose mode only
|
|
58
58
|
// // If fragments are too long, we need this to see which fragment it was
|
|
59
|
-
// console.log(`Created fragment: `, objectID, fragment.url || node.url, fragment.html.length); // eslint-disable-line no-console
|
|
60
59
|
|
|
61
|
-
return [
|
|
62
|
-
...fragmentAccumulator,
|
|
63
|
-
{...node, ...fragment, objectID: objectID}
|
|
64
|
-
];
|
|
60
|
+
return [...fragmentAccumulator, {...node, ...fragment, objectID: objectID}];
|
|
65
61
|
}, []);
|
|
66
62
|
|
|
67
63
|
return [...recordAccumulator, ...records];
|
|
@@ -78,7 +74,7 @@ module.exports._testReduceFragmentsUnderHeadings = reduceFragmentsUnderHeadings;
|
|
|
78
74
|
module.exports.transformToAlgoliaObject = (posts, ignoreSlugs) => {
|
|
79
75
|
const algoliaObjects = [];
|
|
80
76
|
|
|
81
|
-
posts.map(
|
|
77
|
+
posts.map(post => {
|
|
82
78
|
// Define the properties we need for Algolia
|
|
83
79
|
const algoliaPost = {
|
|
84
80
|
objectID: post.id,
|
|
@@ -100,13 +96,13 @@ module.exports.transformToAlgoliaObject = (posts, ignoreSlugs) => {
|
|
|
100
96
|
}
|
|
101
97
|
|
|
102
98
|
if (post.tags && post.tags.length) {
|
|
103
|
-
post.tags.forEach(
|
|
99
|
+
post.tags.forEach(tag => {
|
|
104
100
|
algoliaPost.tags.push({name: tag.name, slug: tag.slug});
|
|
105
101
|
});
|
|
106
102
|
}
|
|
107
103
|
|
|
108
104
|
if (post.authors && post.authors.length) {
|
|
109
|
-
post.authors.forEach(
|
|
105
|
+
post.authors.forEach(author => {
|
|
110
106
|
algoliaPost.authors.push({name: author.name, slug: author.slug});
|
|
111
107
|
});
|
|
112
108
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/algolia-fragmenter",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"repository":
|
|
3
|
+
"version": "0.2.9",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/TryGhost/algolia.git",
|
|
7
|
+
"directory": "packages/algolia-fragmenter"
|
|
8
|
+
},
|
|
5
9
|
"author": "Ghost Foundation",
|
|
6
10
|
"license": "MIT",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"dev": "echo \"Implement me!\"",
|
|
10
|
-
"test": "NODE_ENV=testing mocha './test/**/*.test.js'",
|
|
11
|
-
"lint": "eslint . --ext .js --cache",
|
|
12
|
-
"posttest": "yarn lint"
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24"
|
|
13
13
|
},
|
|
14
|
+
"main": "index.js",
|
|
14
15
|
"files": [
|
|
15
16
|
"index.js",
|
|
16
17
|
"lib"
|
|
@@ -18,13 +19,13 @@
|
|
|
18
19
|
"publishConfig": {
|
|
19
20
|
"access": "public"
|
|
20
21
|
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"mocha": "10.2.0",
|
|
23
|
-
"should": "13.2.3",
|
|
24
|
-
"sinon": "17.0.0"
|
|
25
|
-
},
|
|
26
22
|
"dependencies": {
|
|
27
23
|
"algolia-html-extractor": "0.0.1"
|
|
28
24
|
},
|
|
29
|
-
"
|
|
30
|
-
|
|
25
|
+
"scripts": {
|
|
26
|
+
"dev": "echo \"Implement me!\"",
|
|
27
|
+
"test": "NODE_ENV=testing vitest run --root .",
|
|
28
|
+
"lint": "oxlint --quiet . && oxfmt --check .",
|
|
29
|
+
"posttest": "pnpm lint"
|
|
30
|
+
}
|
|
31
|
+
}
|