-
Notifications
You must be signed in to change notification settings - Fork 18
make giscus comment section opt-in to comply with ASF policy
#106
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| (() => { | ||
| const container = document.getElementById('comment-thread'); | ||
| const btnLoad = document.getElementById('giscus-load'); | ||
| const btnRevoke = document.getElementById('giscus-revoke'); | ||
| const consentKey = 'apache_datafusion_giscus_consent'; | ||
|
|
||
| if (!container || !btnLoad || !btnRevoke) return; | ||
|
|
||
| // Giscus configuration | ||
| // | ||
| // <script src="https://giscus.app/client.js" | ||
| // data-repo="apache/datafusion-site" | ||
| // data-repo-id="R_kgDOL8FTzw" | ||
| // data-category="Announcements" | ||
| // data-category-id="DIC_kwDOL8FTz84Csqua" | ||
| // data-mapping="title" | ||
| // data-strict="1" | ||
| // data-reactions-enabled="1" | ||
| // data-emit-metadata="0" | ||
| // data-input-position="bottom" | ||
| // data-theme="light" | ||
| // data-lang="en" | ||
| // data-loading="lazy" | ||
| // crossorigin="anonymous" | ||
| // async> | ||
| // </script> | ||
|
|
||
| function injectGiscus() { | ||
| // Avoid double-injection if already present | ||
| if (document.querySelector('script[data-giscus]') || | ||
| container.querySelector('iframe.giscus-frame')) { | ||
| btnLoad.hidden = true; | ||
| btnRevoke.hidden = false; | ||
| return; | ||
| } | ||
|
|
||
| btnLoad.disabled = true; | ||
|
|
||
| const s = document.createElement('script'); | ||
| s.setAttribute('data-giscus', ''); // marker attribute to identify the script | ||
| s.src = 'https://giscus.app/client.js'; | ||
| s.setAttribute('data-repo', 'apache/datafusion-site'); | ||
| s.setAttribute('data-repo-id', 'R_kgDOL8FTzw'); | ||
| s.setAttribute('data-category', 'Announcements'); | ||
| s.setAttribute('data-category-id', 'DIC_kwDOL8FTz84Csqua'); | ||
| s.setAttribute('data-mapping', 'title'); | ||
| s.setAttribute('data-strict', '1'); | ||
| s.setAttribute('data-reactions-enabled', '1'); | ||
| s.setAttribute('data-emit-metadata', '0'); | ||
| s.setAttribute('data-input-position', 'bottom'); | ||
| s.setAttribute('data-theme', 'light'); | ||
| s.setAttribute('data-lang', 'en'); | ||
| s.setAttribute('data-loading', 'lazy'); | ||
| s.crossOrigin = 'anonymous'; | ||
| s.async = true; | ||
|
|
||
| s.addEventListener('error', () => { | ||
| btnLoad.disabled = false; | ||
| }); | ||
|
|
||
| const observer = new MutationObserver(() => { | ||
| if (container.querySelector('iframe.giscus-frame')) { | ||
| btnLoad.hidden = true; | ||
| btnRevoke.hidden = false; | ||
| btnLoad.disabled = false; | ||
| observer.disconnect(); | ||
| } | ||
| }); | ||
| observer.observe(container, { childList: true, subtree: true }); | ||
|
|
||
| container.appendChild(s); | ||
| } | ||
|
|
||
| function removeGiscus() { | ||
| container.querySelectorAll('iframe.giscus-frame').forEach((el) => el.remove()); | ||
| container.querySelectorAll('.giscus').forEach((el) => el.remove()); | ||
| document.querySelectorAll('script[data-giscus], script[src^="https://giscus.app"]').forEach((el) => el.remove()); | ||
| container.replaceChildren(); | ||
|
|
||
| btnLoad.hidden = false; | ||
| btnLoad.disabled = false; | ||
| btnRevoke.hidden = true; | ||
| } | ||
|
|
||
| btnLoad.addEventListener('click', () => { | ||
| try { localStorage.setItem(consentKey, 'true'); } catch {} | ||
| injectGiscus(); | ||
| }); | ||
|
|
||
| btnRevoke.addEventListener('click', () => { | ||
| try { localStorage.removeItem(consentKey); } catch {} | ||
| removeGiscus(); | ||
| }); | ||
|
|
||
| try { | ||
| if (localStorage.getItem(consentKey) === 'true') { | ||
| injectGiscus(); | ||
| } | ||
| } catch { | ||
| // Storage unavailable; require click each time. | ||
| } | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,30 @@ | ||
| <!-- | ||
| Enable giscuss comments: Allows comments on the blogs posted as | ||
| https://github.com/apache/datafusion-site/discussions | ||
| <!-- | ||
| Comments Section | ||
| Loaded only after explicit visitor consent to comply with ASF policy. | ||
| --> | ||
|
|
||
| More details on https://github.com/apache/datafusion-site/issues/80 | ||
| --> | ||
| <div id="article_comments"> | ||
| <div id="comment_thread"></div> | ||
| <div id="comments"> | ||
| <hr> | ||
| <h3>Comments</h3> | ||
|
|
||
| <script src="https://giscus.app/client.js" | ||
| data-repo="apache/datafusion-site" | ||
| data-repo-id="R_kgDOL8FTzw" | ||
| data-category="Announcements" | ||
| data-category-id="DIC_kwDOL8FTz84Csqua" | ||
| data-mapping="title" | ||
| data-strict="1" | ||
| data-reactions-enabled="1" | ||
| data-emit-metadata="0" | ||
| data-input-position="bottom" | ||
| data-theme="preferred_color_scheme" | ||
| data-lang="en" | ||
| data-loading="lazy" | ||
| crossorigin="anonymous" | ||
| async> | ||
| </script> | ||
| <!-- Local loader script --> | ||
| <script src="/content/js/giscus-consent.js" defer></script> | ||
|
|
||
| <!-- Consent UI --> | ||
| <div id="giscus-consent"> | ||
| <p> | ||
| We use <a href="https://giscus.app/">Giscus</a> for comments, powered by GitHub Discussions. | ||
| To respect your privacy, comments will load only when you choose. | ||
| </p> | ||
|
|
||
| <div class="consent-actions"> | ||
| <button id="giscus-load" type="button">Show Comments</button> | ||
| <button id="giscus-revoke" type="button" hidden>Hide Comments</button> | ||
| </div> | ||
|
|
||
| <noscript>JavaScript is required to load comments from Giscus.</noscript> | ||
| </div> | ||
|
|
||
| <!-- Container where Giscus will render --> | ||
| <div id="comment-thread"></div> | ||
| </div> | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.