TysonMN / tysonmn.github.io

Blog of Tyson Williams about software engineering and functional programming
https://tysonwilliams.coding.blog/
MIT License
3 stars 7 forks source link

Dynamically changing theme #33

Closed utterances-bot closed 2 years ago

utterances-bot commented 2 years ago

Lock Hunter

https://tysonwilliams.coding.blog/2021-06-21_lock_hunter

im-coder-lg commented 2 years ago

How DO you change the theme dynamically? it is damn interesting! Hats off to you sir! :octocat:

TysonMN commented 2 years ago

My blog uses CODEDOC, which has this DarkLight component. In my markdown, I add both the dark- and light-themed utterance scripts (which are extracted into this custom component). It is dynamic in that it changes without a full reload of the page (complements to CODEDOC and the DarkLight component), but it also does two queries to the GitHub API to obtain the comments (one for the dark theme and one for the light theme). Of course it would be better if there were only one such query, but I don't care to optimize this at the moment.

im-coder-lg commented 2 years ago

Whoa. Cool!

TysonMN commented 2 years ago

I might even requery each time the theme is changed.

im-coder-lg commented 2 years ago

So, do I need any plugin for this to work?

TysonMN commented 2 years ago

I don't think so. I think CODEDOC is enough.

im-coder-lg commented 2 years ago

Not that, for Utterances!

TysonMN commented 2 years ago

Oh. I have no idea how Utterances works. Sorry.

im-coder-lg commented 2 years ago

Oh. I have no idea how Utterances works. Sorry.

Ah, it's simple. Every comment is made with a bot, which converts that comment to a new issue in your specific repository. And then, it uses a GET request(I think, because it uses JS for the script.) to get the latest comment in THAT SPECIFIC ISSUE into the JS that got posted there.

TysonMN commented 2 years ago

Oh. Sorry again. I meant that I don't understand how the frontend works. I understand how the backend works. I thought you were trying to figure out some frontend solution.