💄 Add comment counter in home & page.
This commit is contained in:
parent
d609eecb23
commit
e1c088c355
2
assets/js/third-party/comments/waline.js
vendored
2
assets/js/third-party/comments/waline.js
vendored
@ -5,6 +5,7 @@ NexT.plugins.comments.waline = function() {
|
|||||||
|| !NexT.utils.checkDOMExist(element)) return;
|
|| !NexT.utils.checkDOMExist(element)) return;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
comment,
|
||||||
emoji,
|
emoji,
|
||||||
imguploader,
|
imguploader,
|
||||||
pageview,
|
pageview,
|
||||||
@ -39,6 +40,7 @@ NexT.plugins.comments.waline = function() {
|
|||||||
locale,
|
locale,
|
||||||
el : element,
|
el : element,
|
||||||
pageview : pageview,
|
pageview : pageview,
|
||||||
|
comment : comment,
|
||||||
emoji : emoji,
|
emoji : emoji,
|
||||||
imageUploader : imguploader,
|
imageUploader : imguploader,
|
||||||
wordLimit : wordlimit,
|
wordLimit : wordlimit,
|
||||||
|
35
assets/js/third-party/others/counter.js
vendored
Normal file
35
assets/js/third-party/others/counter.js
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/* Page's view & comment counter plugin */
|
||||||
|
NexT.plugins.others.counter = function() {
|
||||||
|
let busz_postview = false;
|
||||||
|
let pageview_js = undefined;
|
||||||
|
let comment_js = undefined;
|
||||||
|
|
||||||
|
const busz = NexT.CONFIG.busuanzi;
|
||||||
|
if (busz != undefined && busz.pageview) {
|
||||||
|
busz_postview = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Here can append others pageview & comment plugin
|
||||||
|
const waline = NexT.CONFIG.waline;
|
||||||
|
if (waline != undefined){
|
||||||
|
if(!busz_postview && waline.cfg.pageview) {
|
||||||
|
pageview_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js[0]);
|
||||||
|
NexT.utils.getScript(pageview_js, function(){
|
||||||
|
Waline.pageviewCount({
|
||||||
|
serverURL: waline.cfg.serverurl
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (waline.cfg.comment) {
|
||||||
|
comment_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js[1]);
|
||||||
|
NexT.utils.getScript(comment_js, function(){
|
||||||
|
Waline.commentCount({
|
||||||
|
serverURL: waline.cfg.serverurl
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
21
assets/js/third-party/others/pageview.js
vendored
21
assets/js/third-party/others/pageview.js
vendored
@ -1,21 +0,0 @@
|
|||||||
/* Waline pageview plugin */
|
|
||||||
NexT.plugins.others.pageview = function() {
|
|
||||||
const busz = NexT.CONFIG.busuanzi;
|
|
||||||
if (busz != undefined && busz.pageview) return;
|
|
||||||
|
|
||||||
let pageview_js = undefined;
|
|
||||||
|
|
||||||
// Here can append others pageview plugin
|
|
||||||
const waline = NexT.CONFIG.waline;
|
|
||||||
if (waline != undefined && waline.cfg.pageview) {
|
|
||||||
pageview_js = NexT.utils.getCDNResource(NexT.CONFIG.page.pageview.js);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pageview_js == undefined) return;
|
|
||||||
|
|
||||||
NexT.utils.getScript(pageview_js, function(){
|
|
||||||
Waline.pageviewCount({
|
|
||||||
serverURL: waline.cfg.serverurl
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
@ -8,15 +8,15 @@ HTMLElement.prototype.wrap = function (wrapper) {
|
|||||||
|
|
||||||
NexT.utils = {
|
NexT.utils = {
|
||||||
registerImageLoadEvent: function() {
|
registerImageLoadEvent: function() {
|
||||||
var images = document.querySelectorAll('.sidebar img, .post-block img, .vendors-list img');
|
const images = document.querySelectorAll('.sidebar img, .post-block img, .vendors-list img');
|
||||||
|
|
||||||
var callback = (entries) => {
|
const callback = (entries) => {
|
||||||
entries.forEach(item => {
|
entries.forEach(item => {
|
||||||
if (item.intersectionRatio > 0) {
|
if (item.intersectionRatio > 0) {
|
||||||
var ele = item.target;
|
let ele = item.target;
|
||||||
var imgSrc = ele.getAttribute('data-src');
|
let imgSrc = ele.getAttribute('data-src');
|
||||||
if (imgSrc) {
|
if (imgSrc) {
|
||||||
var img = new Image();
|
let img = new Image();
|
||||||
img.addEventListener('load', function() {
|
img.addEventListener('load', function() {
|
||||||
ele.src = imgSrc;
|
ele.src = imgSrc;
|
||||||
}, false);
|
}, false);
|
||||||
@ -28,7 +28,7 @@ NexT.utils = {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
var observer = new IntersectionObserver(callback);
|
const observer = new IntersectionObserver(callback);
|
||||||
images.forEach(img => {
|
images.forEach(img => {
|
||||||
observer.observe(img);
|
observer.observe(img);
|
||||||
});
|
});
|
||||||
@ -125,7 +125,7 @@ NexT.utils = {
|
|||||||
if (laWidget.length > 0) {
|
if (laWidget.length > 0) {
|
||||||
const valIds = [0, 2, 4, 6];
|
const valIds = [0, 2, 4, 6];
|
||||||
const domIds = ['today_site_pv', 'yesterday_site_pv', 'month_site_pv', 'total_site_pv']
|
const domIds = ['today_site_pv', 'yesterday_site_pv', 'month_site_pv', 'total_site_pv']
|
||||||
for (var i in valIds) {
|
for (let i in valIds) {
|
||||||
let pv = NexT.utils.numberFormat(laWidget[valIds[i]].innerText);
|
let pv = NexT.utils.numberFormat(laWidget[valIds[i]].innerText);
|
||||||
document.getElementById(domIds[i]).innerText = pv;
|
document.getElementById(domIds[i]).innerText = pv;
|
||||||
}
|
}
|
||||||
@ -455,7 +455,7 @@ NexT.utils = {
|
|||||||
const comms = document.querySelectorAll('.comment-wrap > div');
|
const comms = document.querySelectorAll('.comment-wrap > div');
|
||||||
if (comms.length <= 1) return;
|
if (comms.length <= 1) return;
|
||||||
comms.forEach(function (item) {
|
comms.forEach(function (item) {
|
||||||
var dis = window.getComputedStyle(item, null).display;
|
let dis = window.getComputedStyle(item, null).display;
|
||||||
item.style.display = dis;
|
item.style.display = dis;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -115,12 +115,18 @@ plugins:
|
|||||||
name: mermaid
|
name: mermaid
|
||||||
version: 9.1.7
|
version: 9.1.7
|
||||||
file: dist/mermaid.min.js
|
file: dist/mermaid.min.js
|
||||||
# 文章访问统计
|
# 文章访问/评论统计
|
||||||
waline:
|
waline:
|
||||||
js:
|
js:
|
||||||
name: '@waline/client'
|
- name: pageview
|
||||||
|
alias_name: '@waline/client'
|
||||||
version: 2.13.0
|
version: 2.13.0
|
||||||
file: dist/pageview.js
|
file: dist/pageview.js
|
||||||
alias: waline
|
alias: waline
|
||||||
|
- name: comment
|
||||||
|
alias_name: '@waline/client'
|
||||||
|
version: 2.13.0
|
||||||
|
file: dist/comment.js
|
||||||
|
alias: waline
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,6 +93,8 @@ PostReadTime:
|
|||||||
other: "{{- .ReadingTime -}}min"
|
other: "{{- .ReadingTime -}}min"
|
||||||
PostViews:
|
PostViews:
|
||||||
other: "Views"
|
other: "Views"
|
||||||
|
PostComments:
|
||||||
|
other: "Comments"
|
||||||
PostTag:
|
PostTag:
|
||||||
other: "Tags"
|
other: "Tags"
|
||||||
PostReadMore:
|
PostReadMore:
|
||||||
|
@ -94,6 +94,8 @@ PostReadTime:
|
|||||||
other: "{{- .ReadingTime -}}分钟"
|
other: "{{- .ReadingTime -}}分钟"
|
||||||
PostViews:
|
PostViews:
|
||||||
other: 浏览
|
other: 浏览
|
||||||
|
PostComments:
|
||||||
|
other: 评论
|
||||||
PostTags:
|
PostTags:
|
||||||
other: 标签
|
other: 标签
|
||||||
PostReadMore:
|
PostReadMore:
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
"title" .Page.Title
|
"title" .Page.Title
|
||||||
-}}
|
-}}
|
||||||
|
|
||||||
{{/* Append waline pageview plugin */}}
|
{{/* Append waline pageview & comment plugin */}}
|
||||||
{{ if and .Site.Params.waline .Site.Params.waline.pageView }}
|
{{ if and .Site.Params.waline ( or .Site.Params.waline.pageView .Site.Params.waline.comment) }}
|
||||||
{{ $pageview := dict
|
{{ $counter := dict
|
||||||
"js" .Site.Data.resources.plugins.waline.js
|
"js" .Site.Data.resources.plugins.waline.js
|
||||||
}}
|
}}
|
||||||
{{ $pageCfg = merge $pageCfg (dict "pageview" $pageview) }}
|
{{ $pageCfg = merge $pageCfg (dict "waline" $counter) }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{/* Append mermaid plugin */}}
|
{{/* Append mermaid plugin */}}
|
||||||
|
@ -27,10 +27,15 @@
|
|||||||
{{ partial "post/header_meta/created_date.html" . }}
|
{{ partial "post/header_meta/created_date.html" . }}
|
||||||
{{ partial "post/header_meta/update_date.html" . }}
|
{{ partial "post/header_meta/update_date.html" . }}
|
||||||
{{ partial "post/header_meta/categories.html" . }}
|
{{ partial "post/header_meta/categories.html" . }}
|
||||||
{{ if .Site.Params.waline.pageView }}
|
|
||||||
{{ if and $.IsHome (not (isset .Params "extlink")) }}
|
{{ if and $.IsHome (not (isset .Params "extlink")) }}
|
||||||
|
<div class="post-meta-items">
|
||||||
|
{{ if .Site.Params.waline.pageView }}
|
||||||
{{ partial "post/header_meta/views.html" . }}
|
{{ partial "post/header_meta/views.html" . }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{ if .Site.Params.waline.comment }}
|
||||||
|
{{ partial "post/header_meta/comments.html" . }}
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{- if not $.IsHome }}
|
{{- if not $.IsHome }}
|
||||||
@ -38,6 +43,9 @@
|
|||||||
{{ partial "post/header_meta/words.html" . }}
|
{{ partial "post/header_meta/words.html" . }}
|
||||||
{{ partial "post/header_meta/readtime.html" . }}
|
{{ partial "post/header_meta/readtime.html" . }}
|
||||||
{{ partial "post/header_meta/views.html" . }}
|
{{ partial "post/header_meta/views.html" . }}
|
||||||
|
{{ if .Site.Params.waline.comment }}
|
||||||
|
{{ partial "post/header_meta/comments.html" . }}
|
||||||
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
11
layouts/partials/post/header_meta/comments.html
Normal file
11
layouts/partials/post/header_meta/comments.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<span class="post-meta-item" title="{{ T "PostComments" }}">
|
||||||
|
<span class="post-meta-item-icon">
|
||||||
|
<i class="far fa-comments"></i>
|
||||||
|
</span>
|
||||||
|
<span class="post-meta-item-text">
|
||||||
|
{{ print (T "PostComments") (T "SymbolColon") }}
|
||||||
|
</span>
|
||||||
|
<span {{ with .Site.Params.waline.comment }}class="waline-comment-count"{{end}} data-path="{{ .RelPermalink | relLangURL }}">
|
||||||
|
<i class="fa fa-sync fa-spin"></i>
|
||||||
|
</span>
|
||||||
|
</span>
|
@ -49,9 +49,9 @@
|
|||||||
{{ if isset .Site.Params "waline" }}
|
{{ if isset .Site.Params "waline" }}
|
||||||
{{ $walinejs := resources.Get "js/third-party/comments/waline.js" }}
|
{{ $walinejs := resources.Get "js/third-party/comments/waline.js" }}
|
||||||
{{ $nextjs = $nextjs | append $walinejs }}
|
{{ $nextjs = $nextjs | append $walinejs }}
|
||||||
{{ if .Site.Params.waline.pageView }}
|
{{ if or .Site.Params.waline.pageView .Site.Params.waline.comment }}
|
||||||
{{ $pageviewjs := resources.Get "js/third-party/others/pageview.js" }}
|
{{ $counterjs := resources.Get "js/third-party/others/counter.js" }}
|
||||||
{{ $nextjs = $nextjs | append $pageviewjs }}
|
{{ $nextjs = $nextjs | append $counterjs }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if isset .Site.Params "giscus" }}
|
{{ if isset .Site.Params "giscus" }}
|
||||||
|
Loading…
Reference in New Issue
Block a user