Merge pull request #1402 from sharelatex/jel-wiki-search-url

Wiki search URL path and section anchors

GitOrigin-RevId: 93565d54c3c352f25b20c03e51efd257b5412021
This commit is contained in:
Alasdair Smith
2019-01-16 10:59:51 +00:00
committed by sharelatex
parent 330f878085
commit 79078ac1bb

View File

@@ -42,8 +42,18 @@ define(['base', 'directives/mathjax', 'services/algolia-search'], function(
}
const buildHitViewModel = function(hit) {
const page_underscored = hit.pageName.replace(/\s/g, '_')
const section_underscored = hit.sectionName.replace(/\s/g, '_')
const pagePath = hit.kb ? 'how-to/' : 'latex/'
const pageSlug = hit.pageName.replace(/\s/g, '_').replace(/\?/g, '%3F')
let section_underscored = ''
if (hit.sectionName && hit.sectionName !== '') {
section_underscored = '#' + hit.sectionName.replace(/\s/g, '_')
}
const section = hit._highlightResult.sectionName
let pageName = hit._highlightResult.pageName.value
if (section && section.value && section !== '') {
pageName += ' - ' + section.value
}
let content = hit._highlightResult.content.value
// Replace many new lines
content = content.replace(/\n\n+/g, '\n\n')
@@ -60,11 +70,8 @@ define(['base', 'directives/mathjax', 'services/algolia-search'], function(
}
content = matching_lines.join('\n...\n')
const result = {
name:
hit._highlightResult.pageName.value +
' - ' +
hit._highlightResult.sectionName.value,
url: `/learn/${page_underscored}#${section_underscored}`,
name: pageName,
url: `/learn/${pagePath}${pageSlug}${section_underscored}`,
content
}
return result