-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
49ca20b
commit 7a0fb31
Showing
10 changed files
with
135 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@sfccdevops/sfcc-docs", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Unofficial community edition of the Salesforce Commerce Cloud developer documentation.", | ||
"license": "MIT", | ||
"author": "Peter Schmalfeldt <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { getMeta } from '@/data/meta' | ||
|
||
export default function handler(req, res) { | ||
// Load Search Function | ||
import('@/markdoc/search.mjs').then(({ search }) => { | ||
try { | ||
// Perform Search | ||
const baseURL = process.env.SITE_URL || 'https://sfccdocs.com' | ||
const results = search(req.query.query, { | ||
limit: req.query.limit ? parseInt(req.query.limit, 10) : 100, | ||
offset: req.query.offset ? parseInt(req.query.offset, 10) : 0, | ||
}) | ||
|
||
// Loop through results | ||
results.map((result, index) => { | ||
// Add additional properties | ||
const parts = result.url.split('#') | ||
const baseUri = parts[0] | ||
const anchor = parts.length > 1 ? `#${parts[1]}` : '' | ||
const deprecated = baseUri.startsWith('/deprecated/') | ||
const meta = getMeta(baseUri, deprecated) | ||
|
||
result.deprecated = deprecated | ||
result.title = meta.title | ||
result.description = meta.description | ||
result.keywords = meta.nav.alt.split(' › ') | ||
result.snippet = result.snippet.split('. ')[0] | ||
result.url = `${baseURL}${result.url}` | ||
result.embed = `${baseURL}${baseUri}?embed=true${anchor}` | ||
|
||
// Remove unneeded properties | ||
delete result.score | ||
|
||
if (result.pageTitle) { | ||
delete result.pageTitle | ||
} | ||
|
||
// Sort properties alphabetically for easier readability | ||
results[index] = Object.keys(result) | ||
.sort() | ||
.reduce((accumulator, key) => { | ||
accumulator[key] = result[key] | ||
|
||
return accumulator | ||
}, {}) | ||
}) | ||
|
||
// Return results | ||
res.status(200).json({ total: results.length, results }) | ||
} catch (error) { | ||
// Return error | ||
res.status(400).json({ error: error.message }) | ||
} | ||
}) | ||
} |