mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 18:00:53 +08:00
feat: 本地搜索增加preload,cdn 配置 closed #859
feat: 搜索內容顯示區域變大 feat: algolia 搜索增加文章內容顯示和高亮 feat: 搜索內容增加 ... 縮略辨識 fix: algolia 第一次進入時會自動搜索 fix: mathjax 顯示不完全的 bug
This commit is contained in:
@@ -51,6 +51,8 @@ algolia_search:
|
|||||||
# Local search
|
# Local search
|
||||||
local_search:
|
local_search:
|
||||||
enable: false
|
enable: false
|
||||||
|
preload: false
|
||||||
|
CDN:
|
||||||
|
|
||||||
# Math (數學)
|
# Math (數學)
|
||||||
# --------------------------------------
|
# --------------------------------------
|
||||||
|
|||||||
@@ -19,7 +19,8 @@
|
|||||||
let localSearch = 'undefined';
|
let localSearch = 'undefined';
|
||||||
if (theme.local_search && theme.local_search.enable) {
|
if (theme.local_search && theme.local_search.enable) {
|
||||||
localSearch = JSON.stringify({
|
localSearch = JSON.stringify({
|
||||||
path: config.search.path,
|
path: theme.local_search.CDN ? theme.local_search.CDN : config.root + config.search.path,
|
||||||
|
preload: theme.local_search.preload,
|
||||||
languages: {
|
languages: {
|
||||||
// search languages
|
// search languages
|
||||||
hits_empty: _p("search.local_search.hits_empty"),
|
hits_empty: _p("search.local_search.hits_empty"),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hexo-theme-butterfly",
|
"name": "hexo-theme-butterfly",
|
||||||
"version": "4.2.0-b1",
|
"version": "4.2.0-b2",
|
||||||
"description": "A Simple and Card UI Design theme for Hexo",
|
"description": "A Simple and Card UI Design theme for Hexo",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -54,14 +54,15 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
|||||||
relatedPosts[i].cover === false
|
relatedPosts[i].cover === false
|
||||||
? relatedPosts[i].randomcover
|
? relatedPosts[i].randomcover
|
||||||
: relatedPosts[i].cover
|
: relatedPosts[i].cover
|
||||||
result += `<div><a href="${this.url_for(relatedPosts[i].path)}" title="${relatedPosts[i].title}">`
|
const title = this.escape_html(relatedPosts[i].title)
|
||||||
|
result += `<div><a href="${this.url_for(relatedPosts[i].path)}" title="${title}">`
|
||||||
result += `<img class="cover" src="${this.url_for(cover)}" alt="cover">`
|
result += `<img class="cover" src="${this.url_for(cover)}" alt="cover">`
|
||||||
if (dateType === 'created') {
|
if (dateType === 'created') {
|
||||||
result += `<div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> ${this.date(relatedPosts[i].created, hexoConfig.date_format)}</div>`
|
result += `<div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> ${this.date(relatedPosts[i].created, hexoConfig.date_format)}</div>`
|
||||||
} else {
|
} else {
|
||||||
result += `<div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> ${this.date(relatedPosts[i].updated, hexoConfig.date_format)}</div>`
|
result += `<div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> ${this.date(relatedPosts[i].updated, hexoConfig.date_format)}</div>`
|
||||||
}
|
}
|
||||||
result += `<div class="title">${relatedPosts[i].title}</div>`
|
result += `<div class="title">${title}</div>`
|
||||||
result += '</div></a></div>'
|
result += '</div></a></div>'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ mjx-container[display],
|
|||||||
.has-jax
|
.has-jax
|
||||||
overflow-x: auto
|
overflow-x: auto
|
||||||
overflow-y: hidden
|
overflow-y: hidden
|
||||||
|
line-height: normal !important
|
||||||
|
|
||||||
.aplayer
|
.aplayer
|
||||||
color: $font-black
|
color: $font-black
|
||||||
|
|||||||
@@ -11,7 +11,8 @@
|
|||||||
color: var(--search-input-color)
|
color: var(--search-input-color)
|
||||||
|
|
||||||
.ais-Hits-list
|
.ais-Hits-list
|
||||||
padding-left: 24px
|
margin: 0
|
||||||
|
padding: 0
|
||||||
@extend .list-beauty
|
@extend .list-beauty
|
||||||
|
|
||||||
a
|
a
|
||||||
@@ -25,12 +26,17 @@
|
|||||||
color: $search-keyword-highlight
|
color: $search-keyword-highlight
|
||||||
font-weight: bold
|
font-weight: bold
|
||||||
|
|
||||||
|
.algolia-hit-item-content
|
||||||
|
margin: 0 0 8px
|
||||||
|
word-break: break-all
|
||||||
|
|
||||||
.ais-Pagination
|
.ais-Pagination
|
||||||
margin: 16px 0 0
|
margin: 20px 0 0
|
||||||
padding: 0
|
padding: 0
|
||||||
text-align: center
|
text-align: center
|
||||||
|
|
||||||
.ais-Pagination-list
|
.ais-Pagination-list
|
||||||
|
margin: 0
|
||||||
padding: 0
|
padding: 0
|
||||||
list-style: none
|
list-style: none
|
||||||
|
|
||||||
@@ -52,7 +58,27 @@
|
|||||||
color: #eee
|
color: #eee
|
||||||
cursor: default
|
cursor: default
|
||||||
|
|
||||||
|
.ais-Pagination-item--disabled
|
||||||
|
visibility: hidden
|
||||||
|
|
||||||
.algolia-logo
|
.algolia-logo
|
||||||
padding-top: 2px
|
padding-top: 2px
|
||||||
width: 80px
|
width: 80px
|
||||||
height: 30px
|
height: 30px
|
||||||
|
|
||||||
|
#algolia-hits
|
||||||
|
> div
|
||||||
|
overflow-y: scroll
|
||||||
|
|
||||||
|
+minWidth768()
|
||||||
|
max-height: calc(80vh - 240px)
|
||||||
|
|
||||||
|
+maxWidth768()
|
||||||
|
height: calc(100vh - 260px)
|
||||||
|
|
||||||
|
.apple
|
||||||
|
#algolia-search
|
||||||
|
#algolia-hits
|
||||||
|
> div
|
||||||
|
+maxWidth768()
|
||||||
|
height: calc(90vh - 260px)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
.search-dialog
|
.search-dialog
|
||||||
position: fixed
|
position: fixed
|
||||||
top: 100px
|
top: 10%
|
||||||
left: 50%
|
left: 50%
|
||||||
z-index: 1001
|
z-index: 1001
|
||||||
display: none
|
display: none
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
|
|
||||||
.search-result-list
|
.search-result-list
|
||||||
overflow-y: auto
|
overflow-y: auto
|
||||||
max-height: 210px
|
max-height: calc(80vh - 130px)
|
||||||
|
|
||||||
+maxWidth768()
|
+maxWidth768()
|
||||||
padding-bottom: 40px
|
padding-bottom: 40px
|
||||||
|
|||||||
@@ -26,16 +26,39 @@ window.addEventListener('load', () => {
|
|||||||
|
|
||||||
const searchClickFn = () => {
|
const searchClickFn = () => {
|
||||||
document.querySelector('#search-button > .search').addEventListener('click', openSearch)
|
document.querySelector('#search-button > .search').addEventListener('click', openSearch)
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchClickFnOnce = () => {
|
||||||
document.getElementById('search-mask').addEventListener('click', closeSearch)
|
document.getElementById('search-mask').addEventListener('click', closeSearch)
|
||||||
document.querySelector('#algolia-search .search-close-button').addEventListener('click', closeSearch)
|
document.querySelector('#algolia-search .search-close-button').addEventListener('click', closeSearch)
|
||||||
}
|
}
|
||||||
|
|
||||||
searchClickFn()
|
const cutContent = content => {
|
||||||
|
if (content === '') return ''
|
||||||
|
|
||||||
window.addEventListener('pjax:complete', function () {
|
const firstOccur = content.indexOf('<mark>')
|
||||||
getComputedStyle(document.querySelector('#algolia-search .search-dialog')).display === 'block' && closeSearch()
|
|
||||||
searchClickFn()
|
let start = firstOccur - 30
|
||||||
})
|
let end = firstOccur + 120
|
||||||
|
let pre = ''
|
||||||
|
let post = ''
|
||||||
|
|
||||||
|
if (start <= 0) {
|
||||||
|
start = 0
|
||||||
|
end = 140
|
||||||
|
} else {
|
||||||
|
pre = '...'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end > content.length) {
|
||||||
|
end = content.length
|
||||||
|
} else {
|
||||||
|
post = '...'
|
||||||
|
}
|
||||||
|
|
||||||
|
let matchContent = pre + content.substring(start, end) + post
|
||||||
|
return matchContent
|
||||||
|
}
|
||||||
|
|
||||||
const algolia = GLOBAL_CONFIG.algolia
|
const algolia = GLOBAL_CONFIG.algolia
|
||||||
const isAlgoliaValid = algolia.appId && algolia.apiKey && algolia.indexName
|
const isAlgoliaValid = algolia.appId && algolia.apiKey && algolia.indexName
|
||||||
@@ -43,38 +66,37 @@ window.addEventListener('load', () => {
|
|||||||
return console.error('Algolia setting is invalid!')
|
return console.error('Algolia setting is invalid!')
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchClient = window.algoliasearch(algolia.appId, algolia.apiKey)
|
|
||||||
const search = instantsearch({
|
const search = instantsearch({
|
||||||
indexName: algolia.indexName,
|
indexName: algolia.indexName,
|
||||||
searchClient
|
searchClient: algoliasearch(algolia.appId, algolia.apiKey),
|
||||||
|
searchFunction(helper) {
|
||||||
|
helper.state.query && helper.search()
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
search.addWidgets([
|
const configure = instantsearch.widgets.configure({
|
||||||
instantsearch.widgets.configure({
|
|
||||||
hitsPerPage: 5
|
hitsPerPage: 5
|
||||||
})
|
})
|
||||||
])
|
|
||||||
|
|
||||||
search.addWidgets([
|
const searchBox = instantsearch.widgets.searchBox({
|
||||||
instantsearch.widgets.searchBox({
|
|
||||||
container: '#algolia-search-input',
|
container: '#algolia-search-input',
|
||||||
showReset: false,
|
showReset: false,
|
||||||
showSubmit: false,
|
showSubmit: false,
|
||||||
placeholder: GLOBAL_CONFIG.algolia.languages.input_placeholder,
|
placeholder: GLOBAL_CONFIG.algolia.languages.input_placeholder,
|
||||||
showLoadingIndicator: true
|
showLoadingIndicator: true
|
||||||
})
|
})
|
||||||
])
|
|
||||||
|
|
||||||
search.addWidgets([
|
const hits = instantsearch.widgets.hits({
|
||||||
instantsearch.widgets.hits({
|
|
||||||
container: '#algolia-hits',
|
container: '#algolia-hits',
|
||||||
templates: {
|
templates: {
|
||||||
item: function (data) {
|
item(data) {
|
||||||
|
console.log(data);
|
||||||
const link = data.permalink ? data.permalink : (GLOBAL_CONFIG.root + data.path)
|
const link = data.permalink ? data.permalink : (GLOBAL_CONFIG.root + data.path)
|
||||||
return `
|
return `
|
||||||
<a href="${link}" class="algolia-hit-item-link">
|
<a href="${link}" class="algolia-hit-item-link">
|
||||||
${data._highlightResult.title.value || 'no-title'}
|
${data._highlightResult.title.value || 'no-title'}
|
||||||
</a>`
|
</a>
|
||||||
|
<p class="algolia-hit-item-content">${cutContent(data._highlightResult.contentStripTruncate.value)}</p>`
|
||||||
},
|
},
|
||||||
empty: function (data) {
|
empty: function (data) {
|
||||||
return (
|
return (
|
||||||
@@ -85,10 +107,8 @@ window.addEventListener('load', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
])
|
|
||||||
|
|
||||||
search.addWidgets([
|
const stats = instantsearch.widgets.stats({
|
||||||
instantsearch.widgets.stats({
|
|
||||||
container: '#algolia-stats',
|
container: '#algolia-stats',
|
||||||
templates: {
|
templates: {
|
||||||
text: function (data) {
|
text: function (data) {
|
||||||
@@ -102,10 +122,8 @@ window.addEventListener('load', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
])
|
|
||||||
|
|
||||||
search.addWidgets([
|
const pagination = instantsearch.widgets.pagination({
|
||||||
instantsearch.widgets.pagination({
|
|
||||||
container: '#algolia-pagination',
|
container: '#algolia-pagination',
|
||||||
totalPages: 5,
|
totalPages: 5,
|
||||||
templates: {
|
templates: {
|
||||||
@@ -115,9 +133,20 @@ window.addEventListener('load', () => {
|
|||||||
next: '<i class="fas fa-angle-right"></i>'
|
next: '<i class="fas fa-angle-right"></i>'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
])
|
|
||||||
|
|
||||||
|
search.addWidgets([configure,searchBox,hits,stats,pagination]) // add the widgets to the instantsearch instance
|
||||||
|
|
||||||
search.start()
|
search.start()
|
||||||
|
|
||||||
|
searchClickFn()
|
||||||
|
searchClickFnOnce()
|
||||||
|
|
||||||
|
window.addEventListener('pjax:complete', () => {
|
||||||
|
getComputedStyle(document.querySelector('#algolia-search .search-dialog')).display === 'block' && closeSearch()
|
||||||
|
searchClickFn()
|
||||||
|
})
|
||||||
|
|
||||||
window.pjax && search.on('render', () => {
|
window.pjax && search.on('render', () => {
|
||||||
window.pjax.refresh(document.getElementById('algolia-hits'))
|
window.pjax.refresh(document.getElementById('algolia-hits'))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
let loadFlag = false
|
let loadFlag = false
|
||||||
|
let dataObj = []
|
||||||
|
const $searchMask = document.getElementById('search-mask')
|
||||||
|
|
||||||
const openSearch = () => {
|
const openSearch = () => {
|
||||||
const bodyStyle = document.body.style
|
const bodyStyle = document.body.style
|
||||||
bodyStyle.width = '100%'
|
bodyStyle.width = '100%'
|
||||||
bodyStyle.overflow = 'hidden'
|
bodyStyle.overflow = 'hidden'
|
||||||
btf.animateIn(document.getElementById('search-mask'), 'to_show 0.5s')
|
btf.animateIn($searchMask, 'to_show 0.5s')
|
||||||
btf.animateIn(document.querySelector('#local-search .search-dialog'), 'titleScale 0.5s')
|
btf.animateIn(document.querySelector('#local-search .search-dialog'), 'titleScale 0.5s')
|
||||||
setTimeout(() => { document.querySelector('#local-search-input input').focus() }, 100)
|
setTimeout(() => { document.querySelector('#local-search-input input').focus() }, 100)
|
||||||
if (!loadFlag) {
|
if (!loadFlag) {
|
||||||
search(GLOBAL_CONFIG.localSearch.path)
|
search()
|
||||||
loadFlag = true
|
loadFlag = true
|
||||||
}
|
}
|
||||||
// shortcut: ESC
|
// shortcut: ESC
|
||||||
@@ -25,35 +28,35 @@ window.addEventListener('load', () => {
|
|||||||
bodyStyle.width = ''
|
bodyStyle.width = ''
|
||||||
bodyStyle.overflow = ''
|
bodyStyle.overflow = ''
|
||||||
btf.animateOut(document.querySelector('#local-search .search-dialog'), 'search_close .5s')
|
btf.animateOut(document.querySelector('#local-search .search-dialog'), 'search_close .5s')
|
||||||
btf.animateOut(document.getElementById('search-mask'), 'to_hide 0.5s')
|
btf.animateOut($searchMask, 'to_hide 0.5s')
|
||||||
}
|
}
|
||||||
|
|
||||||
// click function
|
|
||||||
const searchClickFn = () => {
|
const searchClickFn = () => {
|
||||||
document.querySelector('#search-button > .search').addEventListener('click', openSearch)
|
document.querySelector('#search-button > .search').addEventListener('click', openSearch)
|
||||||
document.getElementById('search-mask').addEventListener('click', closeSearch)
|
|
||||||
document.querySelector('#local-search .search-close-button').addEventListener('click', closeSearch)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
searchClickFn()
|
const searchClickFnOnce = () => {
|
||||||
|
document.querySelector('#local-search .search-close-button').addEventListener('click', closeSearch)
|
||||||
|
$searchMask.addEventListener('click', closeSearch)
|
||||||
|
if (GLOBAL_CONFIG.localSearch.preload) dataObj = fetchData(GLOBAL_CONFIG.localSearch.path)
|
||||||
|
}
|
||||||
|
|
||||||
// pjax
|
// check url is json or not
|
||||||
window.addEventListener('pjax:complete', function () {
|
const isJson = url => {
|
||||||
getComputedStyle(document.querySelector('#local-search .search-dialog')).display === 'block' && closeSearch()
|
const reg = /\.json$/
|
||||||
searchClickFn()
|
return reg.test(url)
|
||||||
})
|
}
|
||||||
|
|
||||||
async function search (path) {
|
const fetchData = async (path) => {
|
||||||
let datas = []
|
let data = []
|
||||||
const typeF = path.split('.')[1]
|
const response = await fetch(path)
|
||||||
const response = await fetch(GLOBAL_CONFIG.root + path)
|
if (isJson(path)) {
|
||||||
if (typeF === 'json') {
|
data = await response.json()
|
||||||
datas = await response.json()
|
} else {
|
||||||
} else if (typeF === 'xml') {
|
|
||||||
const res = await response.text()
|
const res = await response.text()
|
||||||
const t = await new window.DOMParser().parseFromString(res, 'text/xml')
|
const t = await new window.DOMParser().parseFromString(res, 'text/xml')
|
||||||
const a = await t
|
const a = await t
|
||||||
datas = [...a.querySelectorAll('entry')].map(function (item) {
|
data = [...a.querySelectorAll('entry')].map(item =>{
|
||||||
return {
|
return {
|
||||||
title: item.querySelector('title').textContent,
|
title: item.querySelector('title').textContent,
|
||||||
content: item.querySelector('content') && item.querySelector('content').textContent,
|
content: item.querySelector('content') && item.querySelector('content').textContent,
|
||||||
@@ -66,10 +69,18 @@ window.addEventListener('load', () => {
|
|||||||
$loadDataItem.nextElementSibling.style.display = 'block'
|
$loadDataItem.nextElementSibling.style.display = 'block'
|
||||||
$loadDataItem.remove()
|
$loadDataItem.remove()
|
||||||
}
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
const search = () => {
|
||||||
|
if (!GLOBAL_CONFIG.localSearch.preload) {
|
||||||
|
dataObj = fetchData(GLOBAL_CONFIG.localSearch.path)
|
||||||
|
}
|
||||||
|
|
||||||
const $input = document.querySelector('#local-search-input input')
|
const $input = document.querySelector('#local-search-input input')
|
||||||
const $resultContent = document.getElementById('local-search-results')
|
const $resultContent = document.getElementById('local-search-results')
|
||||||
const $loadingStatus = document.getElementById('loading-status')
|
const $loadingStatus = document.getElementById('loading-status')
|
||||||
|
|
||||||
$input.addEventListener('input', function () {
|
$input.addEventListener('input', function () {
|
||||||
const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
||||||
if (keywords[0] !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
|
if (keywords[0] !== '') $loadingStatus.innerHTML = '<i class="fas fa-spinner fa-pulse"></i>'
|
||||||
@@ -79,7 +90,8 @@ window.addEventListener('load', () => {
|
|||||||
if (keywords.length <= 0) return
|
if (keywords.length <= 0) return
|
||||||
let count = 0
|
let count = 0
|
||||||
// perform local searching
|
// perform local searching
|
||||||
datas.forEach(function (data) {
|
dataObj.then(data => {
|
||||||
|
data.forEach(data => {
|
||||||
let isMatch = true
|
let isMatch = true
|
||||||
let dataTitle = data.title ? data.title.trim().toLowerCase() : ''
|
let dataTitle = data.title ? data.title.trim().toLowerCase() : ''
|
||||||
const dataContent = data.content ? data.content.trim().replace(/<[^>]+>/g, '').toLowerCase() : ''
|
const dataContent = data.content ? data.content.trim().replace(/<[^>]+>/g, '').toLowerCase() : ''
|
||||||
@@ -87,9 +99,9 @@ window.addEventListener('load', () => {
|
|||||||
let indexTitle = -1
|
let indexTitle = -1
|
||||||
let indexContent = -1
|
let indexContent = -1
|
||||||
let firstOccur = -1
|
let firstOccur = -1
|
||||||
// only match artiles with not empty titles and contents
|
// only match articles with not empty titles and contents
|
||||||
if (dataTitle !== '' || dataContent !== '') {
|
if (dataTitle !== '' || dataContent !== '') {
|
||||||
keywords.forEach(function (keyword, i) {
|
keywords.forEach((keyword, i) => {
|
||||||
indexTitle = dataTitle.indexOf(keyword)
|
indexTitle = dataTitle.indexOf(keyword)
|
||||||
indexContent = dataContent.indexOf(keyword)
|
indexContent = dataContent.indexOf(keyword)
|
||||||
if (indexTitle < 0 && indexContent < 0) {
|
if (indexTitle < 0 && indexContent < 0) {
|
||||||
@@ -115,6 +127,8 @@ window.addEventListener('load', () => {
|
|||||||
// let end = firstOccur + 50 > dataContent.length ? dataContent.length : firstOccur + 50
|
// let end = firstOccur + 50 > dataContent.length ? dataContent.length : firstOccur + 50
|
||||||
let start = firstOccur - 30
|
let start = firstOccur - 30
|
||||||
let end = firstOccur + 100
|
let end = firstOccur + 100
|
||||||
|
let pre = ''
|
||||||
|
let post = ''
|
||||||
|
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
start = 0
|
start = 0
|
||||||
@@ -122,16 +136,20 @@ window.addEventListener('load', () => {
|
|||||||
|
|
||||||
if (start === 0) {
|
if (start === 0) {
|
||||||
end = 100
|
end = 100
|
||||||
|
} else {
|
||||||
|
pre = '...'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end > dataContent.length) {
|
if (end > dataContent.length) {
|
||||||
end = dataContent.length
|
end = dataContent.length
|
||||||
|
} else {
|
||||||
|
post = '...'
|
||||||
}
|
}
|
||||||
|
|
||||||
let matchContent = dataContent.substring(start, end)
|
let matchContent = dataContent.substring(start, end)
|
||||||
|
|
||||||
// highlight all keywords
|
// highlight all keywords
|
||||||
keywords.forEach(function (keyword) {
|
keywords.forEach(keyword => {
|
||||||
const regS = new RegExp(keyword, 'gi')
|
const regS = new RegExp(keyword, 'gi')
|
||||||
matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||||
dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||||
@@ -141,7 +159,7 @@ window.addEventListener('load', () => {
|
|||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
if (dataContent !== '') {
|
if (dataContent !== '') {
|
||||||
str += '<p class="search-result">' + matchContent + '...</p>'
|
str += '<p class="search-result">' + pre + matchContent + post + '</p>'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
str += '</div>'
|
str += '</div>'
|
||||||
@@ -156,5 +174,15 @@ window.addEventListener('load', () => {
|
|||||||
if (keywords[0] !== '') $loadingStatus.innerHTML = ''
|
if (keywords[0] !== '') $loadingStatus.innerHTML = ''
|
||||||
window.pjax && window.pjax.refresh($resultContent)
|
window.pjax && window.pjax.refresh($resultContent)
|
||||||
})
|
})
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
searchClickFn()
|
||||||
|
searchClickFnOnce()
|
||||||
|
|
||||||
|
// pjax
|
||||||
|
window.addEventListener('pjax:complete', () => {
|
||||||
|
!btf.isHidden($searchMask) && closeSearch()
|
||||||
|
searchClickFn()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user