mirror of
https://github.com/tcsenpai/obsidiangarden_netlify.git
synced 2025-06-07 05:05:20 +00:00
Disable search function if not enabled
This commit is contained in:
parent
411cba93b7
commit
d396af31f2
@ -1,8 +1,15 @@
|
|||||||
const lunrjs = require('lunr');
|
const lunrjs = require('lunr');
|
||||||
|
require('dotenv').config();
|
||||||
|
|
||||||
const handler = async (event) => {
|
const handler = async (event) => {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if (!process.env.dgEnableSearch) {
|
||||||
|
return {
|
||||||
|
statusCode: 200,
|
||||||
|
body: JSON.stringify([])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const search = event.queryStringParameters.term;
|
const search = event.queryStringParameters.term;
|
||||||
if(!search) throw('Missing term query parameter');
|
if(!search) throw('Missing term query parameter');
|
||||||
|
@ -16,8 +16,6 @@ function createIndex(posts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.dgEnableSearch) {
|
const data = require('../../netlify/functions/search/data.json');
|
||||||
const data = require('../../netlify/functions/search/data.json');
|
const index = createIndex(data);
|
||||||
const index = createIndex(data);
|
require('fs').writeFileSync(path.join(__dirname, '../../netlify/functions/search/index.json'), JSON.stringify(index));
|
||||||
require('fs').writeFileSync(path.join(__dirname, '../../netlify/functions/search/index.json'), JSON.stringify(index));
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user