File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed
Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -162,16 +162,8 @@ function getAllFilesInDirectory(articleDirectory, files) {
162162 continue ;
163163 }
164164
165- if ( content . length > 100000 ) {
166- console . warn (
167- `!!! Skipping ${ url } the content is too long.` ,
168- "See https://www.algolia.com/doc/guides/sending-and-managing-data/prepare-your-data/how-to/reducing-object-size/" ,
169- "for solutions." ,
170- ) ;
171- continue ;
172- }
173-
174- to_index . push ( {
165+ const MAX_RECORD_SIZE = 99000 ; // Algolia limit is 100KB, leave buffer
166+ let record = {
175167 title : title . text ,
176168 content : content ,
177169 url : url ,
@@ -180,7 +172,19 @@ function getAllFilesInDirectory(articleDirectory, files) {
180172 color : color ,
181173 version : version ,
182174 keywords : keywords ,
183- } ) ;
175+ } ;
176+
177+ let recordSize = Buffer . byteLength ( JSON . stringify ( record ) , "utf8" ) ;
178+ if ( recordSize > MAX_RECORD_SIZE ) {
179+ const overflow = recordSize - MAX_RECORD_SIZE ;
180+ record . content = content . slice ( 0 , content . length - overflow ) ;
181+ console . warn (
182+ `!!! Truncated ${ url } content to fit within Algolia's 100KB limit (was ${ recordSize } bytes).` ,
183+ "See https://www.algolia.com/doc/guides/sending-and-managing-data/prepare-your-data/how-to/reducing-object-size/" ,
184+ ) ;
185+ }
186+
187+ to_index . push ( record ) ;
184188
185189 console . log ( `... prepared ${ title . text } at ${ url } .` ) ;
186190 }
You can’t perform that action at this time.
0 commit comments