Skip to content

Commit

Permalink
feat: add disqus poll
Browse files Browse the repository at this point in the history
  • Loading branch information
novalagung committed Dec 14, 2024
1 parent f0d6c3b commit 9b42787
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion content/book.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"sitemap"
],
"styles": {
"website": "style-website-v3.css"
"website": "style-website-v4.css"
},
"pdf": {
"margin": {
Expand Down
30 changes: 24 additions & 6 deletions content/script-gitbook-plugin-disqus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@ require([
var useIdentifier = false;
var disqusConfig = null;

function prepareDisqusThreadDOM() {
var id = "disqus_thread";
if ($("#" + id).children().length > 0) {
function prepareDisqusPollDOM() {
if ($("#disqus_poll").children().length > 0) {
return;
}

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

var $disqusDiv = $("<div>", { "id": id });
$(".book-body .page-inner").append($disqusDiv);
function prepareDisqusThreadDOM() {
if ($("#disqus_thread").children().length > 0) {
return;
}

$("#disqus_thread").remove()
$(".book-body .page-inner").append(`<div id="disqus_thread"></div>`);
}

function resetDisqus() {
prepareDisqusPollDOM()
prepareDisqusThreadDOM()
if (typeof DISQUS !== "undefined") {
DISQUS.reset({
Expand Down Expand Up @@ -77,6 +84,17 @@ require([
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();

(function() {
if (document.getElementById('disqus_polls_script')) {
// polls.js script already loaded, don't load a second time
return;
}
var d = document, s = d.createElement('script');
s.id = 'disqus_polls_script';
s.src = 'https://dasarpemrogramangolang.disqus.com/polls.js';
(d.head || d.body).appendChild(s);
})()

resetDisqus();
}

Expand Down
4 changes: 4 additions & 0 deletions content/style-website-v3.css → content/style-website-v4.css
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ ins.adsbygoogle {
}

/* disquss block */
#disqus_poll {
margin: 40px auto 5px;
max-width: 800px;
}
#disqus_thread {
margin: 40px auto 5px;
max-width: 800px;
Expand Down
5 changes: 5 additions & 0 deletions etc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ func webbookPostAdjustment() {
buttonScriptReplacement := `<script async defer src="https://buttons.github.io/buttons.js"></script>` + buttonScriptToFind
htmlString = strings.ReplaceAll(htmlString, buttonScriptToFind, buttonScriptReplacement)

// ==== prevent loading cached disqus.js
disqusScriptToFind := `<script src="gitbook/gitbook-plugin-disqus/plugin.js"></script>`
disqusScriptReplacement := `<script src="gitbook/gitbook-plugin-disqus/plugin.js?` + getVersion() + `"></script>`
htmlString = strings.ReplaceAll(htmlString, disqusScriptToFind, disqusScriptReplacement)

// ==== inject ga4
ga4propertyToFind := `</head>`
ga4propertyReplacement := `<script async src="https://www.googletagmanager.com/gtag/js?id=` + ga4tagId + `"></script>
Expand Down

0 comments on commit 9b42787

Please sign in to comment.