Skip to content
This repository was archived by the owner on Sep 20, 2022. It is now read-only.

Commit 5dbc5c1

Browse files
authored
feat(algolia): hash content for lockfile to trigger reindexing on content change (#660)
1 parent a13a9bf commit 5dbc5c1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.changeset/rude-eagles-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@guild-docs/algolia": patch
3+
---
4+
5+
feat(algolia): hash content for lockfile to trigger reindexing on content change

packages/algolia/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import removeMarkdown from 'remove-markdown';
1313
import algoliasearch from 'algoliasearch';
1414
import matter from 'gray-matter';
1515
import glob from 'glob';
16+
import crypto from 'node:crypto'
1617

1718
import type { AlgoliaRecord, AlgoliaSearchItemTOC, AlgoliaRecordSource, IRoutes } from './types';
1819

@@ -392,14 +393,15 @@ export const indexToAlgolia = async ({
392393

393394
const recordsAsString = JSON.stringify(
394395
sortBy(objects, 'objectID'),
395-
(key, value) => (key === 'content' ? '-' : value),
396+
(key, value) => (key === 'content' ? crypto.createHash('md5').update(value).digest('hex') : value),
396397
2
397398
);
398399

399400
const lockFileExists = existsSync(lockfilePath);
400401
const lockfileContent = JSON.stringify(
402+
// save space but still keep track of content changes
401403
sortBy(JSON.parse(lockFileExists ? readFileSync(lockfilePath, 'utf-8') : '[]'), 'objectID'),
402-
(key, value) => (key === 'content' ? '-' : value),
404+
null,
403405
2
404406
);
405407

0 commit comments

Comments
 (0)