diff --git a/services/web/public/src/main/learn.js b/services/web/public/src/main/learn.js index 4ede627c16..f87a3c54c9 100644 --- a/services/web/public/src/main/learn.js +++ b/services/web/public/src/main/learn.js @@ -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