⚡ Use script to control comments container show.
This commit is contained in:
parent
31f6e21671
commit
d42375820d
@ -34,7 +34,20 @@ NexT.boot.registerEvents = function() {
|
||||
NexT.boot.refresh = function() {
|
||||
|
||||
if (!NexT.CONFIG.page.isPage) return;
|
||||
/**
|
||||
|
||||
NexT.utils.registerSidebarTOC();
|
||||
NexT.utils.replacePostCRLink();
|
||||
NexT.utils.registerCopyCode();
|
||||
NexT.utils.registerPostReward();
|
||||
if(NexT.CONFIG.page.comments) {
|
||||
NexT.utils.initCommontesDispaly();
|
||||
NexT.utils.registerCommonSwitch();
|
||||
} else {
|
||||
NexT.utils.hideCommontes();
|
||||
}
|
||||
|
||||
//TODO
|
||||
/**
|
||||
* Register JS handlers by condition option.
|
||||
* Need to add config option in Front-End at 'scripts/helpers/next-config.js' file.
|
||||
*/
|
||||
@ -44,16 +57,9 @@ NexT.boot.refresh = function() {
|
||||
});*/
|
||||
// NexT.CONFIG.lazyload && window.lozad('.post-body img').observe();
|
||||
// NexT.CONFIG.pangu && window.pangu.spacingPage();
|
||||
|
||||
NexT.utils.replacePostCRLink();
|
||||
NexT.utils.initCommontesDispaly();
|
||||
NexT.CONFIG.copybtn && NexT.utils.registerCopyCode();
|
||||
/*NexT.utils.registerTabsTag();
|
||||
NexT.utils.registerActiveMenuItem();
|
||||
NexT.utils.registerLangSelect();*/
|
||||
NexT.utils.registerSidebarTOC();
|
||||
NexT.utils.registerPostReward();
|
||||
NexT.utils.registerCommonSwitch();
|
||||
/*NexT.utils.wrapTableWithBox();
|
||||
NexT.utils.registerVideoIframe();*/
|
||||
|
||||
|
14
assets/js/third-party/comments/artalk.js
vendored
14
assets/js/third-party/comments/artalk.js
vendored
@ -2,18 +2,18 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const element = '.artalk-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.page.artalk
|
||||
|| !NexT.CONFIG.artalk
|
||||
|| !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.page.artalk.css);
|
||||
const artalk_css = NexT.utils.getCDNResource(NexT.CONFIG.artalk.css);
|
||||
NexT.utils.getStyle(artalk_css, null);
|
||||
|
||||
const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.page.artalk.js);
|
||||
const artalk_js = NexT.utils.getCDNResource(NexT.CONFIG.artalk.js);
|
||||
const {
|
||||
site,
|
||||
placeholder,
|
||||
server,
|
||||
} = NexT.CONFIG.page.artalk.cfg;
|
||||
} = NexT.CONFIG.artalk.cfg;
|
||||
|
||||
NexT.utils.loadComments(element)
|
||||
.then(() => NexT.utils.getScript(artalk_js, {
|
||||
@ -22,11 +22,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
new Artalk({
|
||||
el : element,
|
||||
pageKey : NexT.CONFIG.page.permalink,
|
||||
pageTitle : NexT.CONFIG.page.title,
|
||||
pageKey : NexT.CONFIG.permalink,
|
||||
pageTitle : NexT.CONFIG.title,
|
||||
server : server,
|
||||
site : site,
|
||||
locale : NexT.CONFIG.page.lang,
|
||||
locale : NexT.CONFIG.lang,
|
||||
placeholder : placeholder,
|
||||
darkMode : 'auto'
|
||||
});
|
||||
|
8
assets/js/third-party/comments/giscus.js
vendored
8
assets/js/third-party/comments/giscus.js
vendored
@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const element = '.giscus-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.page.giscus
|
||||
|| !NexT.CONFIG.giscus
|
||||
|| !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
const {
|
||||
@ -14,11 +14,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
reactions,
|
||||
repo,
|
||||
repoid,
|
||||
theme } = NexT.CONFIG.page.giscus.cfg;
|
||||
theme } = NexT.CONFIG.giscus.cfg;
|
||||
|
||||
|
||||
NexT.utils.loadComments(element)
|
||||
.then(() => NexT.utils.getScript(NexT.CONFIG.page.giscus.js, {
|
||||
.then(() => NexT.utils.getScript(NexT.CONFIG.giscus.js, {
|
||||
attributes: {
|
||||
'async' : true,
|
||||
'crossorigin' : 'anonymous',
|
||||
@ -31,7 +31,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
'data-emit-metadata' : emit ? 1:0,
|
||||
'data-input-position' : inputposition,
|
||||
'data-theme' : theme,
|
||||
'data-lang' : NexT.CONFIG.page.lang,
|
||||
'data-lang' : NexT.CONFIG.lang,
|
||||
'data-loading' : 'lazy'
|
||||
},
|
||||
parentNode: document.querySelector(element)
|
||||
|
4
assets/js/third-party/comments/livere.js
vendored
4
assets/js/third-party/comments/livere.js
vendored
@ -2,11 +2,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const element = '#lv-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.page.livere
|
||||
|| !NexT.CONFIG.livere
|
||||
|| !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
NexT.utils.loadComments(element).then(() => {
|
||||
NexT.utils.getScript(NexT.CONFIG.page.livere.js, {
|
||||
NexT.utils.getScript(NexT.CONFIG.livere.js, {
|
||||
attributes: {
|
||||
async: true
|
||||
},
|
||||
|
6
assets/js/third-party/comments/utterances.js
vendored
6
assets/js/third-party/comments/utterances.js
vendored
@ -2,17 +2,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const element = '.utterances-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.page.utterances
|
||||
|| !NexT.CONFIG.utterances
|
||||
|| !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
const {
|
||||
repo,
|
||||
issueterm,
|
||||
label,
|
||||
theme } = NexT.CONFIG.page.utterances.cfg;
|
||||
theme } = NexT.CONFIG.utterances.cfg;
|
||||
|
||||
NexT.utils.loadComments(element)
|
||||
.then(() => NexT.utils.getScript(NexT.CONFIG.page.utterances.js, {
|
||||
.then(() => NexT.utils.getScript(NexT.CONFIG.utterances.js, {
|
||||
attributes: {
|
||||
'async' : true,
|
||||
'crossorigin' : 'anonymous',
|
||||
|
10
assets/js/third-party/comments/waline.js
vendored
10
assets/js/third-party/comments/waline.js
vendored
@ -2,7 +2,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const element = '.waline-container';
|
||||
if (!NexT.CONFIG.page.comments
|
||||
|| !NexT.CONFIG.page.waline
|
||||
|| !NexT.CONFIG.waline
|
||||
|| !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
const {
|
||||
@ -13,13 +13,13 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
requiredmeta,
|
||||
serverurl,
|
||||
wordlimit
|
||||
} = NexT.CONFIG.page.waline.cfg;
|
||||
} = NexT.CONFIG.waline.cfg;
|
||||
|
||||
|
||||
const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.css);
|
||||
const waline_css = NexT.utils.getCDNResource(NexT.CONFIG.waline.css);
|
||||
NexT.utils.getStyle(waline_css, null);
|
||||
|
||||
const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.page.waline.js);
|
||||
const waline_js = NexT.utils.getCDNResource(NexT.CONFIG.waline.js);
|
||||
|
||||
const locale = {
|
||||
placeholder: placeholder
|
||||
@ -39,7 +39,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
wordLimit : wordlimit,
|
||||
requiredMeta : requiredmeta,
|
||||
serverURL : serverurl,
|
||||
lang : NexT.CONFIG.page.lang,
|
||||
lang : NexT.CONFIG.lang,
|
||||
dark : "auto"
|
||||
});
|
||||
|
||||
|
4
assets/js/third-party/share/addthis.js
vendored
4
assets/js/third-party/share/addthis.js
vendored
@ -1,9 +1,9 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const element = '.addthis_inline_share_toolbox';
|
||||
if (!NexT.CONFIG.page.addthis || !NexT.utils.checkDOMExist(element)) return;
|
||||
if (!NexT.CONFIG.addthis || !NexT.utils.checkDOMExist(element)) return;
|
||||
|
||||
const addthis_js = NexT.CONFIG.page.addthis.js + '?pubid=' + NexT.CONFIG.page.addthis.cfg.pubid;
|
||||
const addthis_js = NexT.CONFIG.addthis.js + '?pubid=' + NexT.CONFIG.addthis.cfg.pubid;
|
||||
|
||||
NexT.utils.loadComments(element).then(() => {
|
||||
NexT.utils.getScript(addthis_js, {
|
||||
|
@ -63,6 +63,8 @@ NexT.utils = {
|
||||
* One-click copy code support.
|
||||
*/
|
||||
registerCopyCode: function() {
|
||||
if (!NexT.CONFIG.copybtn) return;
|
||||
|
||||
let figure = document.querySelectorAll('.highlight pre');
|
||||
if (figure.length === 0 || !NexT.CONFIG.copybtn) return;
|
||||
figure.forEach(element => {
|
||||
@ -277,7 +279,7 @@ NexT.utils = {
|
||||
});
|
||||
},
|
||||
|
||||
initCommontesDispaly: function(){
|
||||
initCommontesDispaly: function(){
|
||||
const comms = document.querySelectorAll('.comment-wrap > div');
|
||||
if (comms.length<=1) return;
|
||||
comms.forEach(function(item){
|
||||
@ -302,6 +304,10 @@ NexT.utils = {
|
||||
});
|
||||
},
|
||||
|
||||
hideCommontes:function() {
|
||||
document.querySelector('.post-comments').style.display = 'none';
|
||||
},
|
||||
|
||||
hiddeLodingCmp: function(selector) {
|
||||
const loadding = document.querySelector(selector).previousElementSibling;
|
||||
loadding.style.display = 'none';
|
||||
|
@ -1,6 +1,5 @@
|
||||
{{- $root := . -}}
|
||||
{{- with .Site.Params.comments }}
|
||||
{{- if .enable }}
|
||||
{{- $tc := and .storage (gt (len .nav) 1) }}
|
||||
{{- $active := .active }}
|
||||
{{- $fc := .active }}
|
||||
@ -41,4 +40,3 @@
|
||||
</div>
|
||||
</div>
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
@ -1,63 +1,10 @@
|
||||
<script class="next-config" data-name="page" type="application/json">
|
||||
{{- $pageCnf := dict }}
|
||||
{{- $pageCnf = merge $pageCnf (dict
|
||||
{{- dict
|
||||
"isHome" .IsHome
|
||||
"isPage" .IsPage
|
||||
"lang" .Site.LanguageCode
|
||||
"comments" .Site.Params.comments.enable
|
||||
"comments" (.Params.comments | default .Site.Params.comments.enable)
|
||||
"permalink" (.Page.Permalink | absURL)
|
||||
"path" (.Page.Permalink | path.Base)
|
||||
"title" .Page.Title
|
||||
) }}
|
||||
{{- if .IsPage }}
|
||||
|
||||
{{- with .Site.Params.waline }}
|
||||
{{- $waline := dict
|
||||
"js" $.Site.Data.resources.waline.js
|
||||
"css" $.Site.Data.resources.waline.css
|
||||
"cfg" .
|
||||
}}
|
||||
{{- $pageCnf = merge $pageCnf (dict "waline" $waline) }}
|
||||
{{- end }}
|
||||
|
||||
{{- with .Site.Params.giscus }}
|
||||
{{- $giscus := dict
|
||||
"js" $.Site.Data.resources.giscus.js
|
||||
"cfg" .
|
||||
}}
|
||||
{{- $pageCnf = merge $pageCnf (dict "giscus" $giscus) }}
|
||||
{{- end }}
|
||||
|
||||
{{- with .Site.Params.artalk }}
|
||||
{{- $artalk := dict
|
||||
"js" $.Site.Data.resources.artalk.js
|
||||
"css" $.Site.Data.resources.artalk.css
|
||||
"cfg" .
|
||||
}}
|
||||
{{- $pageCnf = merge $pageCnf (dict "artalk" $artalk) }}
|
||||
{{- end }}
|
||||
|
||||
{{- with .Site.Params.livere }}
|
||||
{{- $livere := dict "js" $.Site.Data.resources.livere.js }}
|
||||
{{- $pageCnf = merge $pageCnf (dict "livere" $livere) }}
|
||||
{{- end }}
|
||||
|
||||
{{- with .Site.Params.utterances }}
|
||||
{{- $utterances := dict
|
||||
"js" $.Site.Data.resources.utterances.js
|
||||
"cfg" .
|
||||
}}
|
||||
{{- $pageCnf = merge $pageCnf (dict "utterances" $utterances) }}
|
||||
{{- end }}
|
||||
|
||||
{{- with .Site.Params.addThisId }}
|
||||
{{- $addthis := dict
|
||||
"js" $.Site.Data.resources.addthis.js
|
||||
"cfg" (dict "pubid" .)
|
||||
}}
|
||||
{{- $pageCnf = merge $pageCnf (dict "addthis" $addthis) }}
|
||||
{{- end }}
|
||||
|
||||
{{- end }}
|
||||
{{- $pageCnf -}}
|
||||
-}}
|
||||
</script>
|
@ -15,14 +15,11 @@
|
||||
{{ $router := index .Site.Data.resources.vendors $vendor }}
|
||||
{{ $globalVars.Set "router" $router }}
|
||||
|
||||
{{ $vendorDict := dict
|
||||
"plugins" $vendor
|
||||
"router" $router
|
||||
}}
|
||||
{{ $config := dict
|
||||
"hostname" .Site.BaseURL
|
||||
"root" "/"
|
||||
"vendor" $vendorDict
|
||||
"lang" .Site.LanguageCode
|
||||
"vendor" (dict "plugins" $vendor "router" $router)
|
||||
"darkmode" .Site.Params.darkmode
|
||||
"version" .Site.Data.config.version
|
||||
"scheme" .Site.Params.scheme
|
||||
@ -32,6 +29,54 @@
|
||||
"lazyload" .Site.Params.lazyload
|
||||
"motion" .Site.Params.motion
|
||||
}}
|
||||
|
||||
{{ with .Site.Params.waline }}
|
||||
{{ $waline := dict
|
||||
"js" $.Site.Data.resources.waline.js
|
||||
"css" $.Site.Data.resources.waline.css
|
||||
"cfg" .
|
||||
}}
|
||||
{{ $config = merge $config (dict "waline" $waline) }}
|
||||
{{ end }}
|
||||
|
||||
{{ with .Site.Params.giscus }}
|
||||
{{ $giscus := dict
|
||||
"js" $.Site.Data.resources.giscus.js
|
||||
"cfg" .
|
||||
}}
|
||||
{{ $config = merge $config (dict "giscus" $giscus) }}
|
||||
{{ end }}
|
||||
|
||||
{{ with .Site.Params.artalk }}
|
||||
{{ $artalk := dict
|
||||
"js" $.Site.Data.resources.artalk.js
|
||||
"css" $.Site.Data.resources.artalk.css
|
||||
"cfg" .
|
||||
}}
|
||||
{{ $config = merge $config (dict "artalk" $artalk) }}
|
||||
{{ end }}
|
||||
|
||||
{{ with .Site.Params.livere }}
|
||||
{{ $livere := dict "js" $.Site.Data.resources.livere.js }}
|
||||
{{ $config = merge $config (dict "livere" $livere) }}
|
||||
{{ end }}
|
||||
|
||||
{{ with .Site.Params.utterances }}
|
||||
{{ $utterances := dict
|
||||
"js" $.Site.Data.resources.utterances.js
|
||||
"cfg" .
|
||||
}}
|
||||
{{ $config = merge $config (dict "utterances" $utterances) }}
|
||||
{{ end }}
|
||||
|
||||
{{ with .Site.Params.addThisId }}
|
||||
{{ $addthis := dict
|
||||
"js" $.Site.Data.resources.addthis.js
|
||||
"cfg" (dict "pubid" .)
|
||||
}}
|
||||
{{ $config = merge $config (dict "addthis" $addthis) }}
|
||||
{{ end }}
|
||||
|
||||
{{ $globalVars.Set "config" $config }}
|
||||
|
||||
{{ return $globalVars.Values }}
|
||||
|
Loading…
Reference in New Issue
Block a user