Comments (4)
Yes, add an element with a giscus
class and it’ll be placed there.
from giscus.
Yeah the giscus script tag loads immediately instead of being in a load
event listener so your script probably gets executed after giscus loads. Either make it run immediately (and put it before the giscus script tag), or add the giscus script tag dynamically: #336 (comment) (you can probably just avoid making the div.giscus
element and put the dynamically created script right where the placeholder is).
from giscus.
Hmmm ... My approach was placing this in the header:
<script>
window.addEventListener('load', function () {
var node_to_replace = document.querySelector('li a[title="PLACEHOLDER"]').parentElement;
var giscus_div = document.createElement('div');
giscus_div.className="giscus";
node_to_replace.replaceWith(giscus_div);
})
</script>
Is that a valid approach?
It is working as in: it is replacing that PLACEHOLDER link with a div with the class giscus
– however giscus is still loading at the end of the page. Maybe some kind of "race condition"?
(I should add that I cannot just add any random content to the page, and thus can't just add a div with a specific class myself. The only thing I can add in that position is links and the only thing I can influence of the links is the title, the href and the text between the a-tags.)
Edit: The site I'm playing around with is https://www.sleepless.sg/1
from giscus.
Sorry for not getting back earlier, @laymonage.
I'm still not sure this is the most elegant solution, but it works, as you can see on https://www.sleepless.sg/1 – and that's what counts for me. 👍
<script>
window.addEventListener('load', function () {
var node_to_replace = document.querySelector('li a[title="PLACEHOLDER"]').parentElement;
var giscus_div = document.createElement('div');
giscus_div.className="giscus";
node_to_replace.replaceWith(giscus_div);
let giscusAttributes = {
"src": "https://giscus.app/client.js",
"data-repo": "xxx",
"data-repo-id": "xxx",
"data-category": "Website Comments",
"data-category-id": "xxx",
"data-mapping": "pathname",
"data-reactions-enabled": "1",
"data-emit-metadata": "0",
"data-theme": light,
"data-lang": "en",
"crossorigin": "anonymous",
"async": "",
};
let giscusScript = document.createElement("script");
Object.entries(giscusAttributes).forEach(([key, value]) => giscusScript.setAttribute(key, value));
document.body.appendChild(giscusScript);
})
</script>
Thank you so much; I appreciate the help a lot!
from giscus.
Related Issues (20)
- Comments not being added nor loaded on private repository HOT 2
- is it down? can't load comments anymore. even on the offical home page. HOT 1
- In multilingual website, unable to distinguish between different language versions of a page
- ReferenceError: exports is not defined HOT 1
- Unable to create discussion with request body. HOT 2
- Proposal: Customize labels for specified users
- [Feature Request] Add the ability to update the comment textarea from the parent page
- URI_TOO_LONG error HOT 1
- New GitHub account creation doesn’t redirect back to Giscus comments in blog
- prevent zoom on mobile device
- help: discussion is correcty created, but reading causes a 404 HOT 1
- 404 - /en/widget is expected to be locally served HOT 4
- Value for `crossorigin` when origins set in giscus.json
- [Suggestion]: Translations though weblate?
- Embedded frame redirects 307 https://github.com/orgs/giscus/discussions/1298 for new script tag from giscus.app HOT 1
- Feature Request: Latest Comments Summary in Home Page HOT 4
- Bug: Crash on unknown locale. (Would you accept a PR?)
- Dynamic theme in Vitepress
- Build fails to generate static pages
- [suggestion] expose font family variables for custom themes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from giscus.