Skip to content
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

fix: add reactive theme content #7218

Merged
merged 4 commits into from
May 6, 2024

Conversation

kieranwv
Copy link

@kieranwv kieranwv commented Mar 7, 2024

Description (required)

In shiki's configuration, I set experimentalThemes: { } as documented, but it doesn't work when I dynamically switch dark mode and light mode.

image

output (1)

Then I checked the official documentation of shiki and found that I need to manually set some css fragments to get reactive dark mode.

image

I replaced the .shiki class name with .astro-code and added the code to my documentation project and now it works fine.

output

I added this usage to the document, hoping to help developers who are unfamiliar with shiki. 😀

Copy link

vercel bot commented Mar 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview May 6, 2024 11:58am

@github-actions github-actions bot added the i18n Anything to do with internationalization & translation efforts - ask @YanThomas for help! label Mar 7, 2024
@astrobot-houston
Copy link
Contributor

Hello! Thank you for opening your first PR to Astro’s Docs! 🎉

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any broken links you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Vercel 🥳

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@Eveeifyeve
Copy link
Contributor

!coauthor

Copy link

github-actions bot commented Mar 7, 2024

Co-authored-by: Houston (Bot) <[email protected]>
Co-authored-by: Eveeifyeve <[email protected]>

@sarah11918
Copy link
Member

Hi @kaivanwong ! This looks really cool!

We did just update our Shiki config though, and now instead of experimentalThemes it's just themes. Would you mind testing and make sure this still works with themes?

(See the updated, live docs now: https://docs.astro.build/en/guides/markdown-content/#shiki-configuration )

I will also ask @delucis to review, but we are a bit busy with launch week, so thank you for your patience as we catch up! 😄

@kieranwv
Copy link
Author

kieranwv commented Mar 12, 2024

Hi @kaivanwong ! This looks really cool!

We did just update our Shiki config though, and now instead of experimentalThemes it's just themes. Would you mind testing and make sure this still works with themes?

(See the updated, live docs now: docs.astro.build/en/guides/markdown-content/#shiki-configuration )

I will also ask @delucis to review, but we are a bit busy with launch week, so thank you for your patience as we catch up! 😄

Sure, I tested themes and it work normaly, thank you.

Also, it will be great if the experimental field names stay as the same. If I upgrade the version of Astro, I don't need to change my code. 😁

@Eveeifyeve
Copy link
Contributor

Hi @kaivanwong ! This looks really cool!

We did just update our Shiki config though, and now instead of experimentalThemes it's just themes. Would you mind testing and make sure this still works with themes?

(See the updated, live docs now: https://docs.astro.build/en/guides/markdown-content/#shiki-configuration )

I will also ask @delucis to review, but we are a bit busy with launch week, so thank you for your patience as we catch up! 😄

Yeah I thought this LGTM Since I would use this feature as well.

@sarah11918
Copy link
Member

Hi @kaivanwong ! We're all catching up now after a busy launch week, and I just noticed the second file changed in this PR, too.

Can you please remove the zh file in this PR? When content changes are proposed to the English site, the PR should contain only a change to the English file, which is treated as the source file for our i18n tracking system.

Only after the English is reviewed, edited, and approved do we consider changes ready for translation. Even small changes to the English site are often revised before publishing, so we ask that you not worry about submitting a translation at the same time, to save you time, and because we have a system for translations already! 🙌

@kieranwv kieranwv force-pushed the fix/shiki-reactive-theme branch from b6c9964 to dcc3340 Compare March 19, 2024 01:24
@github-actions github-actions bot removed the i18n Anything to do with internationalization & translation efforts - ask @YanThomas for help! label Mar 19, 2024
@kieranwv
Copy link
Author

Hi @kaivanwong ! We're all catching up now after a busy launch week, and I just noticed the second file changed in this PR, too.

Can you please remove the zh file in this PR? When content changes are proposed to the English site, the PR should contain only a change to the English file, which is treated as the source file for our i18n tracking system.

Only after the English is reviewed, edited, and approved do we consider changes ready for translation. Even small changes to the English site are often revised before publishing, so we ask that you not worry about submitting a translation at the same time, to save you time, and because we have a system for translations already! 🙌

ok, it doesn't matter, I've seen a major update happening to Astro recently. Now, I droped the commit for the zh file.

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @kaivanwong , thank you for your patience while we discussed this proposed change internally!

We are glad you added the extra information about the astro-code class, and think that's really helpful to have here. We have decided that the exact implementation should be left to Shiki's own docs, since they do have this example there and will keep it updated and maintained. We try whenever possible not to document anything that might change without us knowing if it already exists somewhere else and we can just link to it.

I think adding just a note, and not the specific implementation, calls more attention to Astro's class name, which is really the key idea to get across!

So see what you think of this suggestion!

Comment on lines 616 to 647
#### Light and Dark Mode

To make it reactive to your site's theme, you need to add a short CSS snippet:

```css title="Query-based Dark Mode"
@media (prefers-color-scheme: dark) {
.astro-code,
.astro-code span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
}
```

```css title="Class-based Dark Mode"
html.dark .astro-code,
html.dark .astro-code span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
```

> The class name used in [shiki](https://shiki.style/guide/dual-themes#query-based-dark-mode) is `.shiki`, here you need to use `.astro-code`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Light and Dark Mode
To make it reactive to your site's theme, you need to add a short CSS snippet:
```css title="Query-based Dark Mode"
@media (prefers-color-scheme: dark) {
.astro-code,
.astro-code span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
}
```
```css title="Class-based Dark Mode"
html.dark .astro-code,
html.dark .astro-code span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
```
> The class name used in [shiki](https://shiki.style/guide/dual-themes#query-based-dark-mode) is `.shiki`, here you need to use `.astro-code`.
:::note [Customizing Shiki themes]
Astro code blocks are styled using the `.astro-code` class. When following Shiki's documentation (e.g. to [customize light/dark dual or multiple themes](https://shiki.style/guide/dual-themes#query-based-dark-mode)), be sure to replace the `.shiki` class in the examples with `.astro-code`
:::

I think this note helpfully sends people to a better place to see the example (because Shiki will maintain it and keep it updated in the event that things change) and emphasizes the important point which is the astro-code class used! There may be other situations, not just light and dark mode, where knowing this is helpful to the reader.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😀 Thank you very much for your and I think you are right.

@sarah11918 sarah11918 added the add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. label May 1, 2024
@astrobot-houston
Copy link
Contributor

astrobot-houston commented May 6, 2024

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

Locale File Note
en guides/markdown-content.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @kaivanwong ! I think this note is going to be really helpful, and really call attention to the main point. Thank you for taking the time to contribute this, and welcome to Team Docs! 🥳

@kieranwv
Copy link
Author

kieranwv commented May 6, 2024

Thank you @kaivanwong ! I think this note is going to be really helpful, and really call attention to the main point. Thank you for taking the time to contribute this, and welcome to Team Docs! 🥳

Thank you, and I am happy to be able to make some small contribution. 😸

@sarah11918 sarah11918 merged commit 6c0af6a into withastro:main May 6, 2024
8 checks passed
wpplumber pushed a commit to wpplumber/astro-docs that referenced this pull request May 9, 2024
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Eveeifyeve <[email protected]>
wpplumber pushed a commit to wpplumber/astro-docs that referenced this pull request May 15, 2024
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Eveeifyeve <[email protected]>
wpplumber pushed a commit to wpplumber/astro-docs that referenced this pull request May 15, 2024
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Eveeifyeve <[email protected]>
thomasbnt added a commit to thomasbnt/docs that referenced this pull request Jun 25, 2024
yanthomasdev added a commit that referenced this pull request Jun 25, 2024
* i18n(fr): Update guides/astro-db from #8478

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/backend from #8450

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/backend/google-firebase from #8422

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/cms/apostrophecms from #8480

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/cms/builderio from #8259

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/cms/directus from #8647

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/cms/ghost from #8518

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/cms/statamic from #7119

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/content-collections from #8447

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/data-fetching from #8210

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/deploy/cloudflare from #8421

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/deploy/netlify from #8233

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/deploy/render from #8233

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/deploy/vercel from #8217 (and fix little typos)

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/environment-variables from #8533

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/environment-variables from #8611

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/images from #8447 #8646

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/integrations-guide from #8575

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/integrations-guide/cloudflare from #8211

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/integrations-guide/lit from #8270

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/integrations-guide/markdoc from #8167 (Steeeeps)

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/integrations-guide/preact from #8644

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/integrations-guide/react from #8038

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/integrations-guide/vue from #8295

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/markdown-content from #7218

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/markdown-content from #8167 #8239

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/middleware from #8572

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/prefetch from #8246

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/routing from #8466

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/rss from #8632

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/testing from #8369

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update guides/view-transitions from #8646

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Fix typo in routing.mdx

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Fix links ?

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Fix badge

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Fix badge

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Fix tabs

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Fix tabs

Signed-off-by: Thomas Bonnet <[email protected]>

* Update src/content/docs/fr/guides/environment-variables.mdx

Co-authored-by: pioupia <[email protected]>

* Update src/content/docs/fr/guides/integrations-guide/lit.mdx

Co-authored-by: pioupia <[email protected]>

* Update src/content/docs/fr/guides/integrations-guide/vue.mdx

Co-authored-by: pioupia <[email protected]>

* Update src/content/docs/fr/guides/markdown-content.mdx

Co-authored-by: pioupia <[email protected]>

* Update src/content/docs/fr/guides/middleware.mdx

Co-authored-by: pioupia <[email protected]>

* Update src/content/docs/fr/guides/testing.mdx

Co-authored-by: pioupia <[email protected]>

* Update src/content/docs/fr/guides/testing.mdx

Co-authored-by: pioupia <[email protected]>

* Update src/content/docs/fr/guides/testing.mdx

Co-authored-by: pioupia <[email protected]>

* i18n(fr): Fix links

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): Update `tutorial/6-islands` because CI links err

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): fix links

Signed-off-by: Thomas Bonnet <[email protected]>

* i18n(fr): fix links

Signed-off-by: Thomas Bonnet <[email protected]>

---------

Signed-off-by: Thomas Bonnet <[email protected]>
Co-authored-by: pioupia <[email protected]>
Co-authored-by: Yan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add new content Document something that is not in docs. May require testing, confirmation, or affect other pages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants