//- - author: //- avatar: //- date: //- content: //- tags: //- - tag1 //- - tag2 - page.toc = false #article-container if page.comments !== false && theme.comments.use - commentsJsLoad = true script. (() => { const commentDiv = `!{partial('includes/third-party/comments/index', {}, {cache: true})}` const runDestroy = (shuoshuoComment) => { if (!shuoshuoComment) return for (const [key, fn] of Object.entries(shuoshuoComment)) { if (key.startsWith('destroy')) fn() } } window.addCommentToShuoshuo = e => { const btn = e.target.closest('.shuoshuo-comment-btn') if (!btn) return const ele = btn.closest('.container').nextElementSibling const { shuoshuoComment } = window const isInclude = ele.classList.contains('no-comment') runDestroy(shuoshuoComment) if (isInclude) { ele.classList.remove('no-comment') ele.innerHTML = commentDiv const key = `${location.pathname.replace(/\/$/, '')}?key=${ele.getAttribute('data-key')}` btf.switchComments(ele, key) shuoshuoComment.loadComment && shuoshuoComment.loadComment(ele, key) } } })() if page.shuoshuo_url script. (() => { const limitConfig = !{ JSON.stringify(page.limit || {}) } const sortDataByDate = data => data.sort((a, b) => new Date(b.date) - new Date(a.date)) const filterDataByLimit = (data, limit) => { if (!limit || !limit.type) return data if (limit.type === 'num') return data.slice(0, limit.value) if (limit.type === 'date') { const limitDate = new Date(limit.value) return data.filter(item => new Date(item.date) >= limitDate) } return data }; const formatToTimeZone = (date) => { const fullDate = date.length === 10 ? `${date} 00:00:00` : date const visitorTimeZone = '#{config.timezone}' || Intl.DateTimeFormat().resolvedOptions().timeZone const options = { timeZone: visitorTimeZone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false } const [day, month, year, hour, minute, second] = new Intl.DateTimeFormat('en-GB', options) .format(new Date(fullDate)) .match(/\d+/g) return `${year}-${month}-${day} ${hour}:${minute}:${second}` } const loadShuoshuo = async () => { try { const response = await fetch('!{url_for(page.shuoshuo_url)}') let data = await response.json() data = filterDataByLimit(sortDataByDate(data), limitConfig) const container = document.getElementById('article-container') let start = 0 const renderData = (dataSlice) => { const content = dataSlice.map(item => { const formattedDate = formatToTimeZone(item.date) const tags = item.tags && item.tags.map(tag => `${tag}`).join('') || '' const commentButton = item.key && !{commentsJsLoad} ? `