Sha256: 264af532fc648484bbb3a5eb60144d46dfd8379c8374b32dc881f9865f0241a1

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

    <script async
            crossorigin="anonymous"
            issue-term="{{ site.utterances.issue_term }}"
            label="{{ site.utterances.label }}"
            {%- if site.utterances.follow_site_theme -%}
            onload="initUtterancesTheme()"
            {%- endif -%}
            repo="{{ site.utterances.repo }}"
            src="https://utteranc.es/client.js"
            theme="{{ site.utterances.theme }}">
    </script>

    {%- if site.utterances.follow_site_theme -%}
    <script>
        const setUtterancesTheme = (dataTheme) => {
            const iframe = document.querySelector('.utterances-frame');
            if (iframe) {
                const utterancesTheme = dataTheme === 'dark' ? 'github-dark' : 'github-light'
                const message = {
                    type: 'set-theme',
                    theme: utterancesTheme
                };
                iframe.contentWindow.postMessage(message, 'https://utteranc.es');
            }
        }

        // init theme
        const initUtterancesTheme = () => {
            const iframe = document.querySelector('.utterances-frame');
            if (!iframe) return
            iframe.onload = () => {
                setUtterancesTheme(document.documentElement.getAttribute('data-theme'))
            }
        }

        // dynamic change
        const observer = new MutationObserver((mutationsList, observer) => {
            for (let mutation of mutationsList) {
                if (mutation.type === 'attributes' && mutation.attributeName === 'data-theme') {
                    setUtterancesTheme(document.documentElement.getAttribute('data-theme'))
                }
            }
        });
        observer.observe(document.documentElement, {attributes: true, childList: false, subtree: false});
    </script>
    {%- endif -%}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
redeyed-jekyll-theme-0.1.7 _includes/extensions/comments/utterances.html
redeyed-jekyll-theme-0.1.6 _includes/extensions/comments/utterances.html
redeyed-jekyll-theme-0.1.5 _includes/extensions/comments/utterances.html
redeyed-jekyll-theme-0.1.4 _includes/extensions/comments/utterances.html
redeyed-jekyll-theme-0.1.3 _includes/extensions/comments/utterances.html
redeyed-jekyll-theme-0.1.2 _includes/extensions/comments/utterances.html
redeyed-jekyll-theme-0.1.1 _includes/extensions/comments/utterances.html