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