mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-12 22:17:06 +08:00
💥 支持雙評論系統配置/評論配置整理
✨ 增加mac light 代碼框 ✨ 增加文章過期提醒配置 ✨ 文章copyright 可單獨配置 ✨ card-category 中category名稱和數字限制一行顯示 ✨ 簡繁轉換優化,placeholder文字也會被轉換 🐛 修復配置PWA參數時,如果網站是子目錄時,會出現加載不到文件的bugs 調整當card-category有收縮按鈕時的顯示佈局
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
$(function () {
|
||||
var loadFlag = false
|
||||
let loadFlag = false
|
||||
$('a.social-icon.search').on('click', function () {
|
||||
$('body').css({
|
||||
width: '100%',
|
||||
@@ -22,7 +22,7 @@ $(function () {
|
||||
})
|
||||
})
|
||||
|
||||
var closeSearch = function () {
|
||||
const closeSearch = function () {
|
||||
$('body').css('width', '')
|
||||
$('body').css('overflow', '')
|
||||
$('.search-dialog').css({
|
||||
@@ -48,7 +48,7 @@ $(function () {
|
||||
dataType: 'xml',
|
||||
success: function (xmlResponse) {
|
||||
// get the contents from search data
|
||||
var datas = $('entry', xmlResponse).map(function () {
|
||||
const datas = $('entry', xmlResponse).map(function () {
|
||||
return {
|
||||
title: $('title', this).text(),
|
||||
content: $('content', this).text(),
|
||||
@@ -56,29 +56,29 @@ $(function () {
|
||||
}
|
||||
}).get()
|
||||
|
||||
var $input = $('#local-search-input input')[0]
|
||||
var $resultContent = $('#local-hits')[0]
|
||||
const $input = $('#local-search-input input')[0]
|
||||
const $resultContent = $('#local-hits')[0]
|
||||
$input.addEventListener('input', function () {
|
||||
var str = '<div class="search-result-list">'
|
||||
var keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
||||
let str = '<div class="search-result-list">'
|
||||
const keywords = this.value.trim().toLowerCase().split(/[\s]+/)
|
||||
$resultContent.innerHTML = ''
|
||||
if (this.value.trim().length <= 0) {
|
||||
$('.local-search-stats__hr').hide()
|
||||
return
|
||||
}
|
||||
var count = 0
|
||||
let count = 0
|
||||
// perform local searching
|
||||
datas.forEach(function (data) {
|
||||
var isMatch = true
|
||||
let isMatch = true
|
||||
if (!data.title || data.title.trim() === '') {
|
||||
data.title = 'Untitled'
|
||||
}
|
||||
var dataTitle = data.title.trim().toLowerCase()
|
||||
var dataContent = data.content.trim().replace(/<[^>]+>/g, '').toLowerCase()
|
||||
var dataUrl = data.url
|
||||
var indexTitle = -1
|
||||
var indexContent = -1
|
||||
var firstOccur = -1
|
||||
let dataTitle = data.title.trim().toLowerCase()
|
||||
const dataContent = data.content.trim().replace(/<[^>]+>/g, '').toLowerCase()
|
||||
const dataUrl = data.url
|
||||
let indexTitle = -1
|
||||
let indexContent = -1
|
||||
let firstOccur = -1
|
||||
// only match artiles with not empty titles and contents
|
||||
if (dataTitle !== '' || dataContent !== '') {
|
||||
keywords.forEach(function (keyword, i) {
|
||||
@@ -101,11 +101,11 @@ $(function () {
|
||||
|
||||
// show search results
|
||||
if (isMatch) {
|
||||
var content = data.content.trim().replace(/<[^>]+>/g, '')
|
||||
const content = data.content.trim().replace(/<[^>]+>/g, '')
|
||||
if (firstOccur >= 0) {
|
||||
// cut out 130 characters
|
||||
var start = firstOccur - 30
|
||||
var end = firstOccur + 100
|
||||
let start = firstOccur - 30
|
||||
let end = firstOccur + 100
|
||||
|
||||
if (start < 0) {
|
||||
start = 0
|
||||
@@ -119,11 +119,11 @@ $(function () {
|
||||
end = content.length
|
||||
}
|
||||
|
||||
var matchContent = content.substring(start, end)
|
||||
let matchContent = content.substring(start, end)
|
||||
|
||||
// highlight all keywords
|
||||
keywords.forEach(function (keyword) {
|
||||
var regS = new RegExp(keyword, 'gi')
|
||||
const regS = new RegExp(keyword, 'gi')
|
||||
matchContent = matchContent.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||
dataTitle = dataTitle.replace(regS, '<span class="search-keyword">' + keyword + '</span>')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user