|
|
@@ -1,19 +1,4 @@
|
|
|
import _ from 'lodash'
|
|
|
-/* eslint-disable
|
|
|
- camelcase,
|
|
|
- node/handle-callback-err,
|
|
|
- max-len,
|
|
|
- no-return-assign,
|
|
|
-*/
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
-/*
|
|
|
- * decaffeinate suggestions:
|
|
|
- * DS101: Remove unnecessary use of Array.from
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
- * DS207: Consider shorter variations of null checks
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
- */
|
|
|
import App from '../base'
|
|
|
import '../directives/mathjax'
|
|
|
import '../services/algolia-search'
|
|
|
@@ -27,24 +12,24 @@ App.controller(
|
|
|
|
|
|
$scope.clearSearchText = function () {
|
|
|
$scope.searchQueryText = ''
|
|
|
- return updateHits([])
|
|
|
+ updateHits([])
|
|
|
}
|
|
|
|
|
|
$scope.safeApply = function (fn) {
|
|
|
const phase = $scope.$root.$$phase
|
|
|
if (phase === '$apply' || phase === '$digest') {
|
|
|
- return $scope.$eval(fn)
|
|
|
+ $scope.$eval(fn)
|
|
|
} else {
|
|
|
- return $scope.$apply(fn)
|
|
|
+ $scope.$apply(fn)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
const buildHitViewModel = function (hit) {
|
|
|
const pagePath = hit.kb ? 'how-to/' : 'latex/'
|
|
|
const pageSlug = encodeURIComponent(hit.pageName.replace(/\s/g, '_'))
|
|
|
- let section_underscored = ''
|
|
|
+ let sectionUnderscored = ''
|
|
|
if (hit.sectionName && hit.sectionName !== '') {
|
|
|
- section_underscored = '#' + hit.sectionName.replace(/\s/g, '_')
|
|
|
+ sectionUnderscored = '#' + hit.sectionName.replace(/\s/g, '_')
|
|
|
}
|
|
|
const section = hit._highlightResult.sectionName
|
|
|
let pageName = hit._highlightResult.pageName.value
|
|
|
@@ -57,40 +42,40 @@ App.controller(
|
|
|
content = content.replace(/\n\n+/g, '\n\n')
|
|
|
const lines = content.split('\n')
|
|
|
// Only show the lines that have a highlighted match
|
|
|
- const matching_lines = []
|
|
|
- for (const line of Array.from(lines)) {
|
|
|
+ const matchingLines = []
|
|
|
+ for (const line of lines) {
|
|
|
if (!/^\[edit\]/.test(line)) {
|
|
|
content += line + '\n'
|
|
|
if (/<em>/.test(line)) {
|
|
|
- matching_lines.push(line)
|
|
|
+ matchingLines.push(line)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- content = matching_lines.join('\n...\n')
|
|
|
+ content = matchingLines.join('\n...\n')
|
|
|
const result = {
|
|
|
name: pageName,
|
|
|
- url: `/learn/${pagePath}${pageSlug}${section_underscored}`,
|
|
|
+ url: `/learn/${pagePath}${pageSlug}${sectionUnderscored}`,
|
|
|
content,
|
|
|
}
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
- var updateHits = (hits, hits_total = 0) => {
|
|
|
+ var updateHits = (hits, hitsTotal = 0) => {
|
|
|
$scope.safeApply(() => {
|
|
|
$scope.hits = hits
|
|
|
- $scope.hits_total = hits_total
|
|
|
+ $scope.hits_total = hitsTotal
|
|
|
})
|
|
|
}
|
|
|
|
|
|
$scope.search = function () {
|
|
|
$scope.processingSearch = true
|
|
|
const query = $scope.searchQueryText
|
|
|
- if (query == null || query.length === 0) {
|
|
|
+ if (!query || query.length === 0) {
|
|
|
updateHits([])
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- return algoliaSearch.searchWiki(
|
|
|
+ algoliaSearch.searchWiki(
|
|
|
query,
|
|
|
{
|
|
|
hitsPerPage: $scope.config_hits_per_page,
|
|
|
@@ -98,10 +83,10 @@ App.controller(
|
|
|
function (err, response) {
|
|
|
$scope.processingSearch = false
|
|
|
if (response.hits.length === 0) {
|
|
|
- return updateHits([])
|
|
|
+ updateHits([])
|
|
|
} else {
|
|
|
const hits = _.map(response.hits, buildHitViewModel)
|
|
|
- return updateHits(hits, response.nbHits)
|
|
|
+ updateHits(hits, response.nbHits)
|
|
|
}
|
|
|
}
|
|
|
)
|