-
-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a client API? #134
Comments
Hey @ABeltramo, thanks for the suggestion! I added support to change giscus configuration on-the-fly using |
Hi @laymonage thank you for your work, I wasn't expecting a solution that fast! There are a few issues though:
Chrome seems to silently fail, I don't get the error message but content is not refreshed. Here's the code I'm using: let frame = document.querySelector("iframe.giscus-frame");
frame.contentWindow.postMessage({
term: term,
repo: "games-on-whales/gow"
}, location.origin) |
Hey @ABeltramo, thanks for the report!
|
Here the first two are on page load, after that, changing page seems to not trigger a load on your side. |
@ABeltramo Ah, I just realized: you need to wrap the object in this format: frame.contentWindow.postMessage({
giscus: {
setConfig: {
term: term,
repo: "games-on-whales/gow",
}
}
}, 'https://giscus.app') Sorry if it doesn't seem so intuitive. The reason is:
This is why I added a boilerplate example in the guide: function sendMessage<T>(message: T) {
const iframe = document.querySelector<HTMLIFrameElement>('iframe.giscus-frame');
if (!iframe) return;
iframe.contentWindow.postMessage({ giscus: message }, 'https://giscus.app');
}
sendMessage({
setConfig: {
theme: 'https://giscus.app/themes/custom_example.css',
reactionsEnabled: false,
}
}); It seems to work on my website: (Sorry for the screen glitch, screen recording doesn't seem to work well on my linux setup.) |
Thank you for your patience, it works perfectly! 🎉 |
@ABeltramo No problem, I admit it is quite easy to miss -- the docs were written hastily. Glad you got it sorted out! 👍 |
First off, thanks for this project, I love it!
I don't like a full refresh on each page change so I added barba.js in order to load the pages over AJAX instead. This obviously broke giscus, I hacked around a solution that involves changing the iframe
src
on page change via JS but I was wondering if there's a better way to solve this.I don't know if that's possible but will you consider adding a JS client API so that we can programmatically load the discussion?
You can see my tiny js code here and you can see it in action at https://games-on-whales.github.io/gow/
The text was updated successfully, but these errors were encountered: