0

I'm building a blog using nuxt.js/content, I want to apply dark mode using the plugin color mode.

how can I apply the dark mode to the articles?

I tried to do dark: prose-dark, didn't work.

<script>
export default {
  async asyncData({ $content, params }) {
    const post = await $content('posts', params.slug).fetch()
    return { post }
  }
}
</script>


<template>
  <div class="wrapper p-5 mt-20">
    <div class="max-w-screen-lg mx-auto px-3 py-5">
      <h1 class="text-6xl text-gray-800 font-medium"> {{ post.title }}</h1>
      <div class="img max-w-full mx-auto m-5">
        <img :src="require(`~/assets/${post.cover}`)" :alt="post.title" class="rounded-xl shadow-lg">
      </div>
    </div>
    <nuxt-content class="prose prose-lg max-w-screen-lg mx-auto px-3 my-5" :document="post" />
  </div>
</template>
kissu
  • 40,416
  • 14
  • 65
  • 133
Aymane Max
  • 182
  • 11
  • What is prose dark: https://github.com/tailwindlabs/tailwindcss-typography#color-modifiers ? – kissu May 15 '21 at 12:09
  • @kissu a customized shared styles I added to the `tailwind.config.js`, that I found here: https://github.com/nuxt/content/blob/939caf36c547a6b4af6e303c52ed5989a5dea2f0/packages/theme-docs/src/tailwind.config.js#L92 – Aymane Max May 15 '21 at 13:38
  • Did you told your browser to use dark mode? https://stackoverflow.com/a/59223868/8816585 – kissu May 15 '21 at 16:45
  • @kissu yes, I have a component to switch the theme – Aymane Max May 16 '21 at 00:21
  • Do you have a [repro]? – kissu May 16 '21 at 00:45
  • No I'm just asking if anyone tried to do the dark mode, using content and color mode.. – Aymane Max May 16 '21 at 02:15
  • I'm asking for it because it is probably working well (and `nuxt/content` is not relevant here IMO). Probably an issue in your tailwind config file. – kissu May 16 '21 at 09:00

1 Answers1

3

Here is the boilerplate: https://github.com/kissu/nuxt-tailwind-typography-darkmode-boilerplate

It comes with:

This is basically an updated version of the tailwind configuration for the @nuxt/content-theme-docs without being stuck to write documentation files only. (there is maybe a way of doing this out of the box but I did not found it)

This configuration was heavily inspired by this awesome post from Adam: https://github.com/tailwindlabs/tailwindcss-typography/issues/69#issuecomment-752946920

I'm not sure what tailwindcss-dark-mode is really used for since it is not really active and that the few variants that I've tried are already working out of the box with Tailwind 2. But I found this interesting issue in case it may be helpful one day: https://github.com/ChanceArthur/tailwindcss-dark-mode/issues/37#issue-681948280

The current configuration (tailwind.config.js) is essentially relying on toggling buttons at the top of the page because of darkMode: 'class'. If you set it to media, you can either toggle it in your system or go to Chrome's dev tools and ctrl + shift + p and choose your any prefers-color-scheme for testing purposes.

enter image description here

kissu
  • 40,416
  • 14
  • 65
  • 133