Skip to content

Commit 0fb80e3

Browse files
authored
upload search index (#1500)
Signed-off-by: serg <[email protected]>
1 parent f17bd6d commit 0fb80e3

File tree

5 files changed

+4716
-5
lines changed

5 files changed

+4716
-5
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010

1111
# MacOS indexing files
1212
.DS_Store
13+
14+
# Local Netlify folder
15+
.netlify
16+
17+
.env
18+
node_modules

functions/deploy-succeeded.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const atomicalgolia = require('atomic-algolia')
2+
3+
const response = (status, body) => {
4+
return {
5+
statusCode: status,
6+
body: body
7+
}
8+
}
9+
10+
exports.handler = (event, context, callback) => {
11+
if (!process.env.ALGOLIA_APP_ID || !process.env.ALGOLIA_ADMIN_KEY) {
12+
console.log('Not used in this context')
13+
callback(null, response(204, 'no content'))
14+
return
15+
}
16+
17+
const indexFile = require(process.env.ALGOLIA_INDEX_FILE)
18+
const indexName = process.env.ALGOLIA_INDEX_NAME
19+
20+
atomicalgolia(indexName, indexFile, {verbose: true}, (error, result) => {
21+
if (error) {
22+
console.error(error.message)
23+
callback(error.message, response(500, JSON.stringify({ error: error.message })))
24+
return
25+
}
26+
27+
console.log('Status: ok. TaskID: ', result.taskID)
28+
callback(null, response(200, 'ok'))
29+
})
30+
}

netlify.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
[build.environment]
2+
HUGO_VERSION = "0.75.1"
3+
14
[context.production]
25
command = "hugo --minify"
36

4-
[context.production.environment]
5-
HUGO_VERSION = "0.75.1"
6-
77
[context.deploy-preview]
88
command = "hugo -D -F -b $DEPLOY_PRIME_URL"
99

10-
[context.deploy-preview.environment]
11-
HUGO_VERSION = "0.75.1"
10+
[functions]
11+
directory = "functions"
12+
13+
[functions."deploy-succeeded"]
14+
included_files = ["public/search.json"]

0 commit comments

Comments
 (0)