[src/compl] fix MDN response handler
This commit is contained in:
parent
9a7c67edc4
commit
bc135d48e9
|
@ -991,24 +991,14 @@ completions.md = {
|
||||||
|
|
||||||
completions.md.callback = (response) => {
|
completions.md.callback = (response) => {
|
||||||
const res = JSON.parse(response.text)
|
const res = JSON.parse(response.text)
|
||||||
return res.documents.map((s) => {
|
return res.documents.map((s) =>
|
||||||
let excerpt = escape(s.excerpt)
|
createSuggestionItem(`
|
||||||
if (excerpt.length > 240) {
|
|
||||||
excerpt = `${excerpt.slice(0, 240)}…`
|
|
||||||
}
|
|
||||||
res.query.split(" ").forEach((q) => {
|
|
||||||
excerpt = excerpt.replace(new RegExp(q, "gi"), "<strong>$&</strong>")
|
|
||||||
})
|
|
||||||
const title = escape(s.title)
|
|
||||||
const slug = escape(s.slug)
|
|
||||||
return createSuggestionItem(`
|
|
||||||
<div>
|
<div>
|
||||||
<div class="title"><strong>${title}</strong></div>
|
<div class="title"><strong>${s.title}</strong></div>
|
||||||
<div style="font-size:0.8em"><em>${slug}</em></div>
|
<div style="font-size:0.8em"><em>${s.slug}</em></div>
|
||||||
<div>${excerpt}</div>
|
<div>${s.summary}</div>
|
||||||
</div>
|
</div>
|
||||||
`, { url: `https://developer.mozilla.org/${s.locale}/docs/${s.slug}` })
|
`, { url: `https://developer.mozilla.org/${s.locale}/docs/${s.slug}` }))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NPM registry search
|
// NPM registry search
|
||||||
|
|
2
util.js
2
util.js
|
@ -133,7 +133,7 @@ util.processMaps = (maps, aliases, siteleader) => {
|
||||||
|
|
||||||
const fullDescription = `#${category} ${description}`
|
const fullDescription = `#${category} ${description}`
|
||||||
|
|
||||||
if (mapObj.map !== undefined) {
|
if (typeof mapObj.map !== "undefined") {
|
||||||
map(alias, mapObj.map)
|
map(alias, mapObj.map)
|
||||||
} else {
|
} else {
|
||||||
mapkey(key, fullDescription, callback, opts)
|
mapkey(key, fullDescription, callback, opts)
|
||||||
|
|
Loading…
Reference in New Issue