@redpanda-data/docs-extensions-and-macros 3.1.0 → 3.1.2

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.
@@ -188,7 +188,8 @@ function generateIndex (playbook, contentCatalog, { indexLatestOnly = false, exc
188
188
  objectID: urlPath + page.pub.url,
189
189
  titles: titles,
190
190
  keywords: keywords,
191
- _tags: [tag]
191
+ type: 'Doc',
192
+ _tags: [tag, 'docs']
192
193
  }
193
194
 
194
195
  algolia[cname][version].push(indexItem)
@@ -3,9 +3,12 @@
3
3
  const generateIndex = require('./generate-index')
4
4
  const chalk = require('chalk')
5
5
  const algoliasearch = require('algoliasearch')
6
+ const http = require('http')
7
+ const https = require('https')
6
8
  const fs = require('fs')
7
9
  const path = require('path')
8
10
  const _ = require('lodash')
11
+ process.env.UV_THREADPOOL_SIZE=16
9
12
 
10
13
  /**
11
14
  * Algolia indexing for an Antora documentation site.
@@ -26,8 +29,14 @@ function register({
26
29
  var client
27
30
  var index
28
31
 
29
- // Connect and authenticate with Algolia
30
- client = algoliasearch(process.env.ALGOLIA_APP_ID, process.env.ALGOLIA_ADMIN_API_KEY)
32
+ const httpAgent = new http.Agent({ keepAlive: true, maxSockets: 100 });
33
+ const httpsAgent = new https.Agent({ keepAlive: true, maxSockets: 100 });
34
+
35
+ // Connect and authenticate with Algolia using the custom agent
36
+ client = algoliasearch(process.env.ALGOLIA_APP_ID, process.env.ALGOLIA_ADMIN_API_KEY, {
37
+ httpAgent: httpAgent,
38
+ httpsAgent: httpsAgent
39
+ })
31
40
  index = client.initIndex(process.env.ALGOLIA_INDEX_NAME)
32
41
 
33
42
  if (Object.keys(unknownOptions).length) {
@@ -58,6 +67,7 @@ function register({
58
67
 
59
68
  let totalObjectsToUpdate = 0
60
69
  let totalObjectsToAdd = 0
70
+ const objectsToDelete = []
61
71
 
62
72
  for (const c of Object.keys(algolia)) {
63
73
  for (const v of Object.keys(algolia[c])) {
@@ -72,66 +82,60 @@ function register({
72
82
  objectsToUpdate.push(obj)
73
83
  totalObjectsToUpdate++
74
84
  }
85
+ existingObjectsMap.delete(obj.objectID)
75
86
  } else {
76
87
  objectsToAdd.push(obj)
77
88
  totalObjectsToAdd++
78
89
  }
79
90
  }
80
91
 
81
- // Upload new records only if the objects have been updated or they are new.
82
- // See https://www.algolia.com/doc/api-reference/api-methods/save-objects/
83
- if (objectsToUpdate.length) {
84
- index.saveObjects(objectsToUpdate)
85
- .then(() => {
86
- logger.info(`Updated records for ${c} version ${v}`)
87
- })
88
- .catch(error => {
89
- logger.error(`Error updating objects to Algolia: ${error.message}`)
90
- })
91
- }
92
- if (objectsToAdd.length) {
93
- index.saveObjects(objectsToAdd)
94
- .then(() => {
95
- logger.info(`Added records for ${c} version ${v}`)
96
- })
97
- .catch(error => {
98
- logger.error(`Error adding objects to Algolia: ${error.message}`)
99
- })
100
- }
92
+ const addObjectActions = objectsToAdd.map(object => ({
93
+ action: 'addObject',
94
+ indexName: process.env.ALGOLIA_INDEX_NAME,
95
+ body: object
96
+ }));
97
+
98
+ const updateObjectActions = objectsToUpdate.map(object => ({
99
+ action: 'updateObject',
100
+ indexName: process.env.ALGOLIA_INDEX_NAME,
101
+ body: object
102
+ }));
101
103
 
102
- siteCatalog.addFile({
103
- mediaType: 'application/json',
104
- contents: Buffer.from(JSON.stringify(algolia[c][v])),
105
- src: { stem: `algolia-${c}` },
106
- out: { path: `algolia-${c}-${v}.json` },
107
- pub: { url: `/algolia-${c}-${v}.json`, rootPath: '' }
108
- })
104
+ const batchActions = [...addObjectActions, ...updateObjectActions];
105
+
106
+ // Upload new records only if the objects have been updated or they are new.
107
+ // See https://www.algolia.com/doc/api-reference/api-methods/batch/?client=javascript
108
+ await client.multipleBatch(batchActions).then(() => {
109
+ console.log('Batch operations completed successfully');
110
+ }).catch(error => {
111
+ logger.error(`Error uploading records to Algolia: ${error.message}`);
112
+ });
109
113
  }
110
114
  }
111
115
 
112
- index.setSettings({
113
- attributesForFaceting: ['version', 'product']
114
- })
116
+ for (const [objectID, obj] of existingObjectsMap) {
117
+ if (obj.type === 'Doc' && !obj._tags.includes('apis')) {
118
+ objectsToDelete.push(objectID)
119
+ }
120
+ }
121
+ if (objectsToDelete.length > 0) {
122
+ console.log(objectsToDelete)
123
+ await index.deleteObjects(objectsToDelete).then(() => {
124
+ console.log(`Deleted ${objectsToDelete.length} outdated records`);
125
+ }).catch(error => {
126
+ logger.error(`Error deleting records from Algolia: ${error.message}`);
127
+ });
128
+ }
115
129
 
116
130
  console.log(chalk.green('Updated records:' + totalObjectsToUpdate))
117
131
  console.log(chalk.green('New records:' + totalObjectsToAdd))
118
132
 
119
- totalObjectsToAdd === 0 && totalObjectsToUpdate === 0 && console.log(chalk.green('No changes made'))
120
-
121
- try {
122
- let recordCount = 0
123
-
124
- await index.browseObjects({
125
- query: '',
126
- batch: batch => {
127
- recordCount += batch.length
128
- }
129
- })
133
+ totalObjectsToAdd === 0 && totalObjectsToUpdate === 0 && console.log(chalk.green('No new records uploaded or existing records updated'))
134
+ })
130
135
 
131
- console.log(chalk.green('Total records:', recordCount))
132
- } catch (err) {
133
- logger.error(JSON.stringify(err))
134
- }
136
+ process.on('exit', () => {
137
+ httpAgent.destroy()
138
+ httpsAgent.destroy()
135
139
  })
136
140
  }
137
141
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redpanda-data/docs-extensions-and-macros",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "Antora extensions and macros developed for Redpanda documentation.",
5
5
  "keywords": [
6
6
  "antora",