breaking changes: waline 適配 V2

breaking changes: waline 的 visitor 改為 pageview
feat: algolia 搜索增加文章內容顯示和高亮
feat: 搜索內容顯示區域變大
This commit is contained in:
Jerry
2022-05-03 18:57:59 +08:00
Unverified
parent ec78f66470
commit 5b1473c2c8
21 changed files with 248 additions and 335 deletions

View File

@@ -61,16 +61,24 @@
if block
block
if theme.busuanzi.page_pv
- const commentUse = comments.use
if commentUse && !comments.lazyload
case commentUse[0]
when 'Valine'
if theme.valine.visitor
+pvBlock(url_for(page.path),'leancloud_visitors',page.title)
span.leancloud-visitors-count
when 'Waline'
if theme.waline.pageview
+pvBlock('','','')
span.waline-pageview-count(data-path=url_for(page.path))
when 'Twikoo'
if theme.twikoo.visitor
+pvBlock('','','')
span#twikoo_visitors
else if theme.busuanzi.page_pv
+pvBlock('','post-meta-pv-cv','')
span#busuanzi_value_page_pv
else if comments.use && !comments.lazyload
if (comments.use.includes('Valine') && theme.valine.visitor) || (comments.use.includes('Waline') && theme.waline.visitor)
+pvBlock(url_for(page.path),'leancloud_visitors',page.title)
span.leancloud-visitors-count
else if (comments.use.includes('Twikoo') && theme.twikoo.visitor)
+pvBlock('','','')
span#twikoo_visitors
if comments.count && !comments.lazyload && page.comments !== false && comments.use
- var whichCount = comments.use[0]
@@ -96,7 +104,7 @@
when 'Waline'
+countBlock
a(href=url_for(page.path) + '#post-comment')
span.waline-comment-count(id=url_for(page.path))
span.waline-comment-count(data-path=url_for(page.path))
when 'Gitalk'
+countBlock
a(href=url_for(page.path) + '#post-comment')

View File

@@ -5,12 +5,13 @@ script.
let initData = {
el: null,
serverURL: '!{theme.waline.serverURL}',
comment: true
}
const waline = new Waline(initData)
const waline = Waline.init(initData)
}
if (typeof Waline === 'function') initWaline()
else getScript('!{url_for(theme.asset.waline)}').then(initWaline)
else getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
}
window.pjax ? loadWaline() : window.addEventListener('load', loadWaline)

View File

@@ -1,23 +1,35 @@
- const { serverURL, visitor, option } = theme.waline
- const { serverURL, option, pageview } = theme.waline
- const { lazyload, count, use } = theme.comments
script.
function loadWaline () {
function insertCSS () {
const link = document.createElement("link")
link.rel = "stylesheet"
link.href = "!{url_for(theme.asset.waline_css)}"
document.head.appendChild(link)
}
function initWaline () {
const waline = new Waline(Object.assign({
const waline = Waline.init(Object.assign({
el: '#waline-wrap',
serverURL: '!{serverURL}',
path: location.pathname,
visitor: !{visitor},
dark: 'html[data-theme="dark"]'
pageview: !{lazyload ? false : pageview},
dark: 'html[data-theme="dark"]',
path: window.location.pathname,
comment: !{lazyload ? false : count},
}, !{JSON.stringify(option)}))
}
if (typeof Waline === 'function') initWaline()
else getScript('!{url_for(theme.asset.waline)}').then(initWaline)
else {
insertCSS()
getScript('!{url_for(theme.asset.waline_js)}').then(initWaline)
}
}
if ('!{theme.comments.use[0]}' === 'Waline' || !!{theme.comments.lazyload}) {
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('waline-wrap'),loadWaline)
if ('!{use[0]}' === 'Waline' || !!{lazyload}) {
if (!{lazyload}) btf.loadComment(document.getElementById('waline-wrap'),loadWaline)
else setTimeout(loadWaline, 0)
} else {
function loadOtherComment () {

View File

@@ -1,5 +1,3 @@
- let { avatar,avatarCDN } = theme.waline
script.
window.addEventListener('load', () => {
const changeContent = (content) => {
@@ -45,11 +43,11 @@ script.
const getComment = () => {
const loadWaline = () => {
Waline.Widget.RecentComments({
Waline.RecentComments({
serverURL: '!{theme.waline.serverURL}',
count: !{theme.newest_comments.limit}
}).then(res => {
const walineArray = res.comments.map(e => {
}).then(({comments}) => {
const walineArray = comments.map(e => {
return {
'content': changeContent(e.comment),
'avatar': e.avatar,
@@ -67,7 +65,7 @@ script.
}
if (typeof Waline === 'function') loadWaline()
else getScript('!{url_for(theme.asset.waline)}').then(loadWaline)
else getScript('!{url_for(theme.asset.waline_js)}').then(loadWaline)
}
const newestCommentInit = () => {

View File

@@ -1,7 +1,7 @@
#algolia-search
.search-dialog
nav.search-nav
span.search-dialog-title= 'Algolia'
span.search-dialog-title= _p('search.title')
button.search-close-button
i.fas.fa-times
@@ -11,6 +11,8 @@
#algolia-search-results
#algolia-hits
#algolia-pagination
#algolia-stats
#algolia-info
.algolia-stats
.algolia-poweredBy
#search-mask

View File

@@ -1,7 +1,7 @@
#local-search
.search-dialog
nav.search-nav
span.search-dialog-title=_p("search.local_search.label")
span.search-dialog-title= _p('search.title')
span#loading-status
button.search-close-button
i.fas.fa-times