Просмотр исходного кода

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

Wiki search URL path and section anchors

GitOrigin-RevId: 93565d54c3c352f25b20c03e51efd257b5412021
Alasdair Smith 7 лет назад
Родитель
Сommit
79078ac1bb
1 измененных файлов с 14 добавлено и 7 удалено
  1. 14 7
      services/web/public/src/main/learn.js

+ 14 - 7
services/web/public/src/main/learn.js

@@ -42,8 +42,18 @@ define(['base', 'directives/mathjax', 'services/algolia-search'], function(
     }
     }
 
 
     const buildHitViewModel = function(hit) {
     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
       let content = hit._highlightResult.content.value
       // Replace many new lines
       // Replace many new lines
       content = content.replace(/\n\n+/g, '\n\n')
       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')
       content = matching_lines.join('\n...\n')
       const result = {
       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
         content
       }
       }
       return result
       return result