retypeapp / retype

Retype is an ✨ ultra-high-performance✨ static site generator that builds a website based on simple text files.
https://retype.com
Other
1.06k stars 204 forks source link

Keep the same active color scheme when navigating through a hub sites #624

Closed patricklafrance closed 1 year ago

patricklafrance commented 1 year ago

Hello!

With the new hub feature of Retype v3.4, would it be possible to keep the same active color scheme (theme) when navigating between the hub sites?

In the following example, my hub site currently has the light color scheme activated while both of my other sites has the dark color scheme activated:

color_scheme

Thank you,

Patrick

geoffreymcgill commented 1 year ago

If the different websites are all hosted under the same domain name, then I think we might be able to make this work.

Theoretically, if you have companyx.github.com/project-a and companyx.github.com/project-b, they can both read from the same web browser local storage.

I don't think this would be possible if the projects are hosted until different domain names or sub-domain names. For example, example.com and sample.com would not be able to share the theme. As well, example.com and docs.example.com might not be able to share the theme, although we need to test and confirm.

I will keep this thread updated with our progress.

patricklafrance commented 1 year ago

Indeed, they would have to be hosted on the same domain, which, in my opinion makes sense for a hub.

geoffreymcgill commented 1 year ago

We also need to build a new System option into the theme selector. So Dark, Light, and System. Or, Day, Night, and System. The System option is currently the default theme option, where the theme will update based on the users OS preferences, but there currently is not an option to switch back to the System (default) option once either Dark or Light has been selected.

If the theme is tracking the System, then all deployments whether they are on the same domain or not will render with the same theme.

patricklafrance commented 1 year ago

While it make sense to add a System option, I wonder how often someone who choosed explicitly to go for a light or dark theme for a website wants to go back to System ?

conanthedev commented 1 year ago

When I started using Retype, I tried the theme switcher button and honestly never knew it defaulted to System. I wanted to open a feature request asking for System support, I searched the issues and found ticket #421, then I cleared my browser cache and was happy to find it defaulted to system.

Personally I change my system theme from Light to Dark daily, because of huge windows in my office. I notice the web sites I manually need to update the themes to match my system.

geoffreymcgill commented 1 year ago

You can manually clear the doc_theme key using the browser developer tools:

Screen Shot 2023-09-10 at 1 03 11 PM

Once the new System option is in place, it will essentially delete the doc_theme value if it exists, which Retype will then revert to its default mode of tracking the system OS theme.

Currently, Retype does not add the doc_theme local storage value until the theme button is clicked the first time.

geoffreymcgill commented 1 year ago

Okay, we might have fixed this issue of persisting the theme across sub-sites within the same domain or sub-domain. Persisting across different domains or even a domain and sub-domain of the same domain is not possible.

It was a relatively simple change but is going to require some testing to confirm. If testing confirms the fix is good, the change will be included in the next release, which is currently scheduled for v3.5.0.

patricklafrance commented 1 year ago

That would work for us as we expect to host all our sites with GitHub Pages and all repositories are under the same organization 🙏🏻

It might be a good idea thought to keep an item in a backlog to investigate if the mecanism could be moved to cookies in order to allow cross domains and sub-domains support.

geoffreymcgill commented 1 year ago

if the mecanism could be moved to cookies in order to allow cross domains and sub-domains support.

It's not possible, at least with local storage, session storage, or cookies.

To make this work across domains or sub-domains would require a centralized service/server. That breaks the Retype decentralized model, so not something we could implement in the short-term. Long term, maybe, as an option might be possible.

patricklafrance commented 1 year ago

Sorry my bad, indeed cookies can't support cross domains but would allow sub-domains support.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#domain_attribute

geoffreymcgill commented 1 year ago

This enhancement has been included in the v3.5.0 release (now available). We have tested but we need some real world projects to upgrade and confirm things are working as expected.

When you get a chance, please upgrade to v3.5.0 and let us know what you think.

patricklafrance commented 1 year ago

Will do tonight!

Thank you for getting this out quickly, really appreciated 🙏

patricklafrance commented 1 year ago

Works pretty well with our hub :)

Thank you 🙏🏻