Skip to content

Commit 451978e

Browse files
committed
feat: add disqus poll
1 parent f0d6c3b commit 451978e

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

content/book.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"sitemap"
99
],
1010
"styles": {
11-
"website": "style-website-v3.css"
11+
"website": "style-website-v4.css"
1212
},
1313
"pdf": {
1414
"margin": {

content/script-gitbook-plugin-disqus.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@ require([
55
var useIdentifier = false;
66
var disqusConfig = null;
77

8-
function prepareDisqusThreadDOM() {
9-
var id = "disqus_thread";
10-
if ($("#" + id).children().length > 0) {
8+
function prepareDisqusPollDOM() {
9+
if ($("#disqus_poll").children().length > 0) {
1110
return;
1211
}
1312

14-
$("#" + id).remove()
13+
$("#disqus_poll").remove()
14+
$(".book-body .page-inner").append(`<div id="disqus_poll" class="disqus_poll" data-disqus-poll-id="391630233761218"></div>`);
15+
}
1516

16-
var $disqusDiv = $("<div>", { "id": id });
17-
$(".book-body .page-inner").append($disqusDiv);
17+
function prepareDisqusThreadDOM() {
18+
if ($("#disqus_thread").children().length > 0) {
19+
return;
20+
}
21+
22+
$("#disqus_thread").remove()
23+
$(".book-body .page-inner").append(`<div id="disqus_thread"></div>`);
1824
}
1925

2026
function resetDisqus() {
27+
prepareDisqusPollDOM()
2128
prepareDisqusThreadDOM()
2229
if (typeof DISQUS !== "undefined") {
2330
DISQUS.reset({
@@ -77,6 +84,17 @@ require([
7784
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
7885
})();
7986

87+
(function() {
88+
if (document.getElementById('disqus_polls_script')) {
89+
// polls.js script already loaded, don't load a second time
90+
return;
91+
}
92+
var d = document, s = d.createElement('script');
93+
s.id = 'disqus_polls_script';
94+
s.src = 'https://dasarpemrogramangolang.disqus.com/polls.js';
95+
(d.head || d.body).appendChild(s);
96+
})()
97+
8098
resetDisqus();
8199
}
82100

content/style-website-v3.css content/style-website-v4.css

+4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ ins.adsbygoogle {
190190
}
191191

192192
/* disquss block */
193+
#disqus_poll {
194+
margin: 40px auto 5px;
195+
max-width: 800px;
196+
}
193197
#disqus_thread {
194198
margin: 40px auto 5px;
195199
max-width: 800px;

0 commit comments

Comments
 (0)