From bedd304160d5334d72e086cd9f183a616f8dae89 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Tue, 23 Jan 2024 11:41:00 -0500 Subject: [PATCH] Remove Giscus from search page (#8777) --- _static/css/custom.css | 5 ++++ _static/js/custom.js | 62 ++++++++++++++++++++++++++++++++++++++++++ _templates/layout.html | 33 ++++++---------------- 3 files changed, 75 insertions(+), 25 deletions(-) diff --git a/_static/css/custom.css b/_static/css/custom.css index e820032a2..694b832c6 100644 --- a/_static/css/custom.css +++ b/_static/css/custom.css @@ -1763,3 +1763,8 @@ p + .classref-constant { padding: 3px 5px; } } + +/* Giscus */ +#godot-giscus { + margin-bottom: 1em; +} diff --git a/_static/js/custom.js b/_static/js/custom.js index e7a103da3..d028dd0f3 100644 --- a/_static/js/custom.js +++ b/_static/js/custom.js @@ -238,6 +238,65 @@ const registerSidebarObserver = (function(){ }; })(); +/** + * Registers Giscus if there's an #godot-giscus container. + * @returns {void} Nothing. + */ +const registerGiscus = function () { + const giscusContainer = document.getElementById("godot-giscus"); + if (giscusContainer == null) { + return; + } + + const removeGiscusContainer = function() { + giscusContainer.remove(); + }; + + const pageNameMetaElement = Array.from(document.head.querySelectorAll("meta")).find((meta) => meta.name === "doc_pagename"); + if (pageNameMetaElement == null) { + removeGiscusContainer(); + return; + } + + const pageNameDenyList = [ + "search" + ]; + if (pageNameDenyList.includes(pageNameMetaElement.content)) { + removeGiscusContainer(); + return; + } + + // Use https://giscus.app/ to regenerate the script tag if needed. + // data-term is set to be language-independent and version-independent, so that comments can be centralized for each page. + // This increases the likelihood that users will encounter comments on less frequently visited pages. + const scriptElement = document.createElement("script"); + scriptElement.src = "https://giscus.app/client.js"; + scriptElement.crossOrigin = "anonymous"; + scriptElement.async = true; + + const dataset = { + repo: "godotengine/godot-docs-user-notes", + repoId: "R_kgDOKuNx0w", + category: "User-contributed notes", + categoryId: "DIC_kwDOKuNx084CbANb", + mapping: "specific", + term: pageNameMetaElement.content, + strict: "1", + reactionsEnabled: "0", + emitMetadata: "0", + inputPosition: "bottom", + theme: "preferred_color_scheme", + lang: "en", + loading: "lazy", + }; + + for (const [key, value] of Object.entries(dataset)) { + scriptElement.dataset[key] = value; + } + + giscusContainer.append(scriptElement); +}; + $(document).ready(() => { // Remove the search match highlights from the page, and adjust the URL in the // navigation history. @@ -425,6 +484,9 @@ $(document).ready(() => { registerOnScrollEvent(mediaQuery); } + + // Giscus + registerGiscus(); }); // Override the default implementation from doctools.js to avoid this behavior. diff --git a/_templates/layout.html b/_templates/layout.html index 9045ee124..2afebc334 100644 --- a/_templates/layout.html +++ b/_templates/layout.html @@ -8,6 +8,7 @@ {% block extrahead -%} + {% endblock -%} {% block linktags -%} @@ -68,31 +69,13 @@ {% block body %}{% endblock %} {% if (not meta or meta.get('allow_comments') != 'False') and godot_show_article_comments %} -
-

User-contributed notes

-

- Please read the User-contributed notes policy before submitting a comment. -

-{# Use https://giscus.app/ to regenerate the script tag if needed. #} -{# data-term is set to be language-independent and version-independent, so that comments can be centralized for each page. #} -{# This increases the likelihood that users will encounter comments on less frequently visited pages. #} - -
+
+
+

User-contributed notes

+

+ Please read the User-contributed notes policy before submitting a comment. +

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