feat: 可設置首頁文章不顯示內容/description

feat: 主頁文章時間和文章頁文章時間可以配置顯示日期還是相對時間
feat: top_img 可配置 [留空(默認色)/顏色/漸變色/圖片鏈接/ false(不顯示top_img)]
feat: footer可配置背景 [留空/false(默認色)/顏色/漸變色/圖片鏈接/true(跟top_img一樣)]
improvement: preloader 在 pjax 下 每個頁面都會加載
improvement: 修改判斷,避免用户設置2個lightbox 而導致報錯(只能設置一個)
improvement: 精確時間顯示 (剛剛/幾分鐘前/幾小時前/幾天前/幾個月前)
improvement: 刪除不必要的語言文件和css
chore: update hexo-renderer-stylus to 2.0.1
This commit is contained in:
Jerry
2020-09-05 17:01:21 +08:00
Unverified
parent 8603db0545
commit 25b0c733dc
27 changed files with 361 additions and 275 deletions

View File

@@ -159,14 +159,18 @@ $(function () {
})
const mql = window.matchMedia('(max-width: 1024px)')
mql.addListener((ev) => {
const $toggleSidebar = $('#toggle-sidebar')
const matchFn = (ev) => {
if (ev.matches) {
if ($sidebar.hasClass('tocOpenPc')) closeSidebar()
} else {
if ($('#toggle-sidebar').hasClass('on')) openSidebar()
if ($toggleSidebar.hasClass('on')) openSidebar()
if ($mobileTocButton.hasClass('open')) closeMobileSidebar('toc')
}
})
}
mql.addListener(matchFn)
document.addEventListener('pjax:send', () => { mql.removeListener(matchFn) })
// toc元素點擊
$sidebar.find('.toc-link').on('click', function (e) {
@@ -345,9 +349,7 @@ $(function () {
* fancybox和 mediumZoom
*/
const addLightBox = function () {
const isMediumZoom = GLOBAL_CONFIG.medium_zoom
const isFancybox = GLOBAL_CONFIG.fancybox
if (isFancybox) {
if (GLOBAL_CONFIG.lightbox === 'fancybox') {
const images = $('#article-container img:not(.gallery-group-img)').not($('a>img'))
images.each(function (i, o) {
const lazyloadSrc = $(o).attr('data-lazy-src') ? $(o).attr('data-lazy-src') : $(o).attr('src')
@@ -363,7 +365,7 @@ $(function () {
buttons: ['slideShow', 'fullScreen', 'thumbs', 'close'],
hash: false
})
} else if (isMediumZoom) {
} else {
const zoom = mediumZoom(document.querySelectorAll('#article-container :not(a)>img'))
zoom.on('open', function (event) {
const photoBg = $(document.documentElement).attr('data-theme') === 'dark' ? '#121212' : '#fff'
@@ -425,14 +427,18 @@ $(function () {
* toc
*/
const tocFn = function () {
$('.toc-child').hide()
const $sidebar = $('#sidebar')
const $tocChild = $sidebar.find('.toc-child')
const $tocLink = $sidebar.find('.toc-link')
const $article = $('#article-container')
$tocChild.hide()
// main of scroll
$(window).scroll(btf.throttle(function (event) {
const currentTop = $(this).scrollTop()
scrollPercent(currentTop)
findHeadPosition(currentTop)
autoScrollToc(currentTop)
}, 100))
// expand toc-item
@@ -444,18 +450,17 @@ $(function () {
}
const scrollPercent = function (currentTop) {
const $dom = $('#article-container')
const docHeight = $dom.height()
const docHeight = $article.height()
const winHeight = $(window).height()
const headerHeight = $dom.offset().top
const headerHeight = $article.offset().top
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : ($(document).height() - winHeight)
const scrollPercent = (currentTop - headerHeight) / (contentMath)
const scrollPercentRounded = Math.round(scrollPercent * 100)
const percentage = (scrollPercentRounded > 100) ? 100
: (scrollPercentRounded <= 0) ? 0
: scrollPercentRounded
$('#sidebar .progress-num').text(percentage)
$('#sidebar .sidebar-toc__progress-bar').animate({
$sidebar.find('.progress-num').text(percentage)
$sidebar.find('.sidebar-toc__progress-bar').animate({
width: percentage + '%'
}, 100)
}
@@ -468,19 +473,32 @@ $(function () {
}
}
const autoScrollToc = function (currentTop, item) {
const activePosition = item.offset().top
const $tocContent = $sidebar.find('.sidebar-toc__content')
const sidebarScrollTop = $tocContent.scrollTop()
if (activePosition > (currentTop + $(window).height() - 100)) {
$tocContent.scrollTop(sidebarScrollTop + 100)
}
if (activePosition < currentTop + 100) {
$tocContent.scrollTop(sidebarScrollTop - 100)
}
}
// find head position & add active class
// DOM Hierarchy:
// ol.toc > (li.toc-item, ...)
// li.toc-item > (a.toc-link, ol.toc-2child > (li.toc-item, ...))
const versionBiggerFive = GLOBAL_CONFIG.hexoversion.split('.')[0] >= 5
const list = $article.find('h1,h2,h3,h4,h5,h6')
const findHeadPosition = function (top) {
// assume that we are not in the post page if no TOC link be found,
// thus no need to update the status
if ($('.toc-link').length === 0) {
if ($tocLink.length === 0) {
return false
}
const list = $('#article-container').find('h1,h2,h3,h4,h5,h6')
let currentId = ''
list.each(function () {
const head = $(this)
@@ -491,18 +509,19 @@ $(function () {
})
if (currentId === '') {
$('.toc-link').removeClass('active')
$('.toc-child').hide()
$tocLink.removeClass('active')
$tocChild.hide()
}
const currentActive = $('.toc-link.active')
const currentActive = $tocLink.filter('.active')
if (currentId && currentActive.attr('href') !== currentId) {
if (isAnchor) updateAnchor(currentId)
$('.toc-link').removeClass('active')
$tocLink.removeClass('active')
const _this = $('.toc-link[href="' + currentId + '"]')
const _this = $tocLink.filter('[href="' + currentId + '"]')
_this.addClass('active')
autoScrollToc(top, _this)
const parents = _this.parents('.toc-child')
// Returned list is in reverse order of the DOM elements
@@ -518,19 +537,6 @@ $(function () {
.find('.toc-child').hide()
}
}
const autoScrollToc = function (currentTop) {
if ($('.toc-link').hasClass('active')) {
const activePosition = $('.active').offset().top
const sidebarScrollTop = $('#sidebar .sidebar-toc__content').scrollTop()
if (activePosition > (currentTop + $(window).height() - 100)) {
$('#sidebar .sidebar-toc__content').scrollTop(sidebarScrollTop + 100)
}
if (activePosition < currentTop + 100) {
$('#sidebar .sidebar-toc__content').scrollTop(sidebarScrollTop - 100)
}
}
}
}
/**
@@ -766,6 +772,14 @@ $(function () {
})
}
const relativeDate = function (selector) {
selector.each((i, o) => {
const $this = $(o)
const timeVal = $this.attr('datetime')
$this.text(btf.diffDate(timeVal, true)).css('display', 'inline')
})
}
const unRefreshFn = function () {
$(window).on('resize', function () {
if (window.innerWidth < 768) adjustMenu(0)
@@ -787,6 +801,12 @@ $(function () {
toggleSidebar()
GLOBAL_CONFIG_SITE.isSidebar && tocFn()
GLOBAL_CONFIG.noticeOutdate !== undefined && addPostOutdateNotice()
GLOBAL_CONFIG.relativeDate.post && relativeDate($('#post-meta time'))
} else {
GLOBAL_CONFIG.relativeDate.homepage && relativeDate($('#recent-posts time'))
GLOBAL_CONFIG.runtime && addRuntime()
addLastPushDate()
toggleCardCategory()
}
sidebarFn()
@@ -794,15 +814,12 @@ $(function () {
GLOBAL_CONFIG.highlight && addHighlightTool()
GLOBAL_CONFIG.isPhotoFigcaption && addPhotoFigcaption()
runJustifiedGallery()
addLightBox()
GLOBAL_CONFIG.lightbox !== 'null' && addLightBox()
scrollFn()
GLOBAL_CONFIG.runtime && addRuntime()
addLastPushDate()
addTableWrap()
clickFnOfTagHide()
tabsFn.clickFnOfTabs()
tabsFn.backToTop()
toggleCardCategory()
switchComments()
}

View File

@@ -102,20 +102,33 @@ var btf = {
const dateNow = new Date()
const datePost = new Date(d)
const dateDiff = dateNow.getTime() - datePost.getTime()
const dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000))
const minute = 1000 * 60
const hour = minute * 60
const day = hour * 24
const month = day * 30
let result
if (more) {
if (dateDiff <= 3600000) { // < 1 hour
result = GLOBAL_CONFIG.date_suffix.one_hour
} else if (dateDiff < 3600000 * 24) { // 1 hour < x < 24 hours
result = Math.floor(dateDiff / 3600000) + ' ' + GLOBAL_CONFIG.date_suffix.hours
} else if (dayDiff >= 1 || dayDiff < 365) { // 1 day < x < 365 days
result = dayDiff + ' ' + GLOBAL_CONFIG.date_suffix.day
} else { // > 365 days
result = d.toLocaleDateString().replace(/\//g, '-')
const monthCount = dateDiff / month
const dayCount = dateDiff / day
const hourCount = dateDiff / hour
const minuteCount = dateDiff / minute
if (monthCount > 12) {
result = datePost.toLocaleDateString().replace(/\//g, '-')
} else if (monthCount >= 1) {
result = parseInt(monthCount) + ' ' + GLOBAL_CONFIG.date_suffix.month
} else if (dayCount >= 1) {
result = parseInt(dayCount) + ' ' + GLOBAL_CONFIG.date_suffix.day
} else if (hourCount >= 1) {
result = parseInt(hourCount) + ' ' + GLOBAL_CONFIG.date_suffix.hour
} else if (minuteCount >= 1) {
result = parseInt(minuteCount) + ' ' + GLOBAL_CONFIG.date_suffix.min
} else {
result = GLOBAL_CONFIG.date_suffix.just
}
} else {
result = dayDiff
result = parseInt(dateDiff / day)
}
return result
},