Skip to content

Commit

Permalink
change the way search works
Browse files Browse the repository at this point in the history
  • Loading branch information
ragudesign committed Jun 17, 2022
1 parent 5a9bca0 commit d489dd5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ yarn-error.log*
# kb
public/search.json
search.json
lib/search-array.js

.vercel
9 changes: 2 additions & 7 deletions pages/api/search.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
const { readFileSync } = require('fs')
const { join } = require('path');
const rawSearchJson = readFileSync(join(process.cwd(), 'public/search.json'), 'utf8');


let searchJson = JSON.parse(rawSearchJson);
import { searchArray } from '../../lib/search-array'

export default (req, res) => {
const results = req.query.q ?
searchJson.filter(kb => kb.title.toLowerCase().includes(req.query.q.toLowerCase())) : []
searchArray.filter(kb => kb.title.toLowerCase().includes(req.query.q.toLowerCase())) : []
res.statusCode = 200
res.setHeader('Content-Type', 'application/json')
res.end(JSON.stringify({ results }))
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ async function buildJSON() {

const titleSlugs = response.data?.kbs.nodes

const fullParams = `${JSON.stringify(titleSlugs)}`
const fullParams = `export const searchArray = ${JSON.stringify(titleSlugs)}`

fs.writeFile(process.cwd() + '/public/search.json', fullParams, function (err) {
fs.writeFile(process.cwd() + '/lib/search-array.js', fullParams, function (err) {
if (err) return console.log(err);
})
}
Expand Down

0 comments on commit d489dd5

Please sign in to comment.