Skip to content

Commit bedd304

Browse files
authored
Remove Giscus from search page (godotengine#8777)
1 parent d7d127f commit bedd304

File tree

3 files changed

+75
-25
lines changed

3 files changed

+75
-25
lines changed

_static/css/custom.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,3 +1763,8 @@ p + .classref-constant {
17631763
padding: 3px 5px;
17641764
}
17651765
}
1766+
1767+
/* Giscus */
1768+
#godot-giscus {
1769+
margin-bottom: 1em;
1770+
}

_static/js/custom.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,65 @@ const registerSidebarObserver = (function(){
238238
};
239239
})();
240240

241+
/**
242+
* Registers Giscus if there's an #godot-giscus container.
243+
* @returns {void} Nothing.
244+
*/
245+
const registerGiscus = function () {
246+
const giscusContainer = document.getElementById("godot-giscus");
247+
if (giscusContainer == null) {
248+
return;
249+
}
250+
251+
const removeGiscusContainer = function() {
252+
giscusContainer.remove();
253+
};
254+
255+
const pageNameMetaElement = Array.from(document.head.querySelectorAll("meta")).find((meta) => meta.name === "doc_pagename");
256+
if (pageNameMetaElement == null) {
257+
removeGiscusContainer();
258+
return;
259+
}
260+
261+
const pageNameDenyList = [
262+
"search"
263+
];
264+
if (pageNameDenyList.includes(pageNameMetaElement.content)) {
265+
removeGiscusContainer();
266+
return;
267+
}
268+
269+
// Use https://giscus.app/ to regenerate the script tag if needed.
270+
// data-term is set to be language-independent and version-independent, so that comments can be centralized for each page.
271+
// This increases the likelihood that users will encounter comments on less frequently visited pages.
272+
const scriptElement = document.createElement("script");
273+
scriptElement.src = "https://giscus.app/client.js";
274+
scriptElement.crossOrigin = "anonymous";
275+
scriptElement.async = true;
276+
277+
const dataset = {
278+
repo: "godotengine/godot-docs-user-notes",
279+
repoId: "R_kgDOKuNx0w",
280+
category: "User-contributed notes",
281+
categoryId: "DIC_kwDOKuNx084CbANb",
282+
mapping: "specific",
283+
term: pageNameMetaElement.content,
284+
strict: "1",
285+
reactionsEnabled: "0",
286+
emitMetadata: "0",
287+
inputPosition: "bottom",
288+
theme: "preferred_color_scheme",
289+
lang: "en",
290+
loading: "lazy",
291+
};
292+
293+
for (const [key, value] of Object.entries(dataset)) {
294+
scriptElement.dataset[key] = value;
295+
}
296+
297+
giscusContainer.append(scriptElement);
298+
};
299+
241300
$(document).ready(() => {
242301
// Remove the search match highlights from the page, and adjust the URL in the
243302
// navigation history.
@@ -425,6 +484,9 @@ $(document).ready(() => {
425484

426485
registerOnScrollEvent(mediaQuery);
427486
}
487+
488+
// Giscus
489+
registerGiscus();
428490
});
429491

430492
// Override the default implementation from doctools.js to avoid this behavior.

_templates/layout.html

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
{% block extrahead -%}
99
<meta name="doc_version" content="{{ version }}" />
1010
<meta name="doc_is_latest" content="{{ godot_is_latest }}" />
11+
<meta name="doc_pagename" content="{{ pagename }}" />
1112
{% endblock -%}
1213

1314
{% block linktags -%}
@@ -68,31 +69,13 @@
6869
{% block body %}{% endblock %}
6970

7071
{% if (not meta or meta.get('allow_comments') != 'False') and godot_show_article_comments %}
71-
<hr>
72-
<h2>User-contributed notes</h2>
73-
<p>
74-
<em>Please read the <a href="https://github.com/godotengine/godot-docs-user-notes/discussions/1">User-contributed notes policy</a> before submitting a comment.</em>
75-
</p>
76-
{# Use https://giscus.app/ to regenerate the script tag if needed. #}
77-
{# data-term is set to be language-independent and version-independent, so that comments can be centralized for each page. #}
78-
{# This increases the likelihood that users will encounter comments on less frequently visited pages. #}
79-
<script src="https://giscus.app/client.js"
80-
data-repo="godotengine/godot-docs-user-notes"
81-
data-repo-id="R_kgDOKuNx0w"
82-
data-category="User-contributed notes"
83-
data-category-id="DIC_kwDOKuNx084CbANb"
84-
data-mapping="specific"
85-
data-term="{{ pagename }}"
86-
data-strict="1"
87-
data-reactions-enabled="0"
88-
data-emit-metadata="0"
89-
data-input-position="bottom"
90-
data-theme="preferred_color_scheme"
91-
data-lang="en"
92-
data-loading="lazy"
93-
crossorigin="anonymous"
94-
async></script>
95-
<br>
72+
<div id="godot-giscus">
73+
<hr>
74+
<h2>User-contributed notes</h2>
75+
<p>
76+
<em>Please read the <a href="https://github.com/godotengine/godot-docs-user-notes/discussions/1">User-contributed notes policy</a> before submitting a comment.</em>
77+
</p>
78+
</div>
9679
{% endif %}
9780

9881
{%- if self.comments()|trim %}

0 commit comments

Comments
 (0)