Skip to content

how to make Utteranc.es theme follow archie's? #90

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

Open
anthonyhan opened this issue Jun 8, 2023 · 1 comment
Open

how to make Utteranc.es theme follow archie's? #90

anthonyhan opened this issue Jun 8, 2023 · 1 comment

Comments

@anthonyhan
Copy link

hello, I am a total beginer in web dev. I want to add comment system named "Utteranc.es" in archie. But I got some problems.

<script src="https://utteranc.es/client.js"
        repo="[ENTER REPO HERE]"
        issue-term="pathname"
        theme="github-dark"
        crossorigin="anonymous"
        async>
</script>

my plan is, the theme of utterances follows archie's dark/light mode.
I tried the way like theme="github-{{mode}}" but failed.
But I can not find a way to do it. Any suggestions would be very appreciated!

@mansoorbarri
Copy link
Contributor

I have been using another theme on my website called hugo-stack. that used a variable to store the value of the theme i.e. light/dark and use that value in theme="github-. the full file looks something like this:

<script src="https://utteranc.es/client.js" 
        repo="{{ .Site.Params.comments.utterances.repo }}"
        issue-term="{{ .Site.Params.comments.utterances.issueTerm }}"
        {{ with .Site.Params.comments.utterances.label }}
        label="{{ . }}"
        {{ end }}
        crossorigin="anonymous"
        async
        >
</script>

<style>
    .utterances {
        max-width: unset;
    }
</style>

<script>
    let utterancesLoaded = false;

    function setUtterancesTheme(theme) {
        let utterances = document.querySelector('.utterances iframe');
        if (utterances) {
            utterances.contentWindow.postMessage(
                {
                    type: 'set-theme',
                    theme: `github-${theme}`
                },
                'https://utteranc.es'
            );
        }
    }

    addEventListener('message', event => {
        if (event.origin !== 'https://utteranc.es') return;

        /// Called when Utterances is ready
        utterancesLoaded = true;
        setUtterancesTheme(document.documentElement.dataset.scheme)
    });

    window.addEventListener('onColorSchemeChange', (e) => {
        if (!utterancesLoaded) return;
        setUtterancesTheme(e.detail)
    })
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants