mirror of
https://github.com/tcsenpai/obsidiangarden_netlify.git
synced 2025-06-06 04:35:20 +00:00
Merge pull request #15 from oleeskild/search
Disable search function if not enabled
This commit is contained in:
commit
a6654e096f
@ -1,8 +1,15 @@
|
||||
const lunrjs = require('lunr');
|
||||
require('dotenv').config();
|
||||
|
||||
const handler = async (event) => {
|
||||
try {
|
||||
|
||||
if (!process.env.dgEnableSearch) {
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: JSON.stringify([])
|
||||
}
|
||||
}
|
||||
|
||||
const search = event.queryStringParameters.term;
|
||||
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 index = createIndex(data);
|
||||
require('fs').writeFileSync(path.join(__dirname, '../../netlify/functions/search/index.json'), JSON.stringify(index));
|
||||
}
|
||||
const data = require('../../netlify/functions/search/data.json');
|
||||
const index = createIndex(data);
|
||||
require('fs').writeFileSync(path.join(__dirname, '../../netlify/functions/search/index.json'), JSON.stringify(index));
|
||||
|
Loading…
x
Reference in New Issue
Block a user