#docs template

12 messages · Page 1 of 1 (latest)

haughty forumBOT
#

Hi @turbid sun. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

If you have set NUXT_PUBLIC_SITE_URL in your .env file but your Open Graph (OG) image is still showing the default Nuxt template image, there are a few things to check based on the knowledge sources:

  1. .env Usage and Build Time
    Environment variables from .env (like NUXT_PUBLIC_SITE_URL) are only loaded at development, build, and generate time. If you update your .env file, you must restart your dev server or rebuild your project for changes to take effect. In production, .env files are not read; you must set environment variables using your hosting platform's configuration or via the command line when starting your server Nuxt .env docs.

  2. Static Site Generation and OG Images
    If you are generating a static site (using nuxt generate), OG images and meta tags are generated at build time. If the environment variable was not set correctly before the build, the generated pages will use the default value. You need to:

    • Set NUXT_PUBLIC_SITE_URL in your .env file.
    • Stop your dev/build process.
    • Run the build/generate command again.
  3. Dynamic OG Images
    If your OG image is generated dynamically (e.g., using a Nuxt OG Image module or similar), ensure that the logic for generating the OG image uses the correct environment variable from useRuntimeConfig().public or useAppConfig() as appropriate. If you are using a static value in your nuxt.config, it will not update unless you rebuild.

#
  1. Nuxt Image and Static Generation
    If you are using Nuxt Image and building a static site, images are optimized and saved at generation time. If SSR is disabled (ssr: false), you need to explicitly prerender image routes using nitro.prerender.routes in your nuxt.config Nuxt Image Static Images.

  2. Browser Cache
    Sometimes, browsers cache OG images aggressively. Try clearing your cache or using a different browser to verify changes.

Summary of steps to fix:

  • Make sure NUXT_PUBLIC_SITE_URL is set in your .env before building.
  • Restart your dev server or rebuild your project after changing .env.
  • For static sites, re-run nuxi generate after updating the environment variable.
  • Ensure your OG image logic references the correct runtime config.
  • If using Nuxt Image with SSR disabled, add image routes to nitro.prerender.routes.

If you follow these steps and the OG image is still not updating, please check your OG image generation logic and ensure it is not hardcoded or cached elsewhere.

For more details, see the official docs on environment variables and Nuxt Image static images.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@turbid sun Kapa.ai is still learning and improving, please let me know how I did by reacting below.

turbid sun
#

ok, and is it possible to permanently set dark mode as the theme? so no colormode switch and only dark mode available

#

ok, and is it possible to permanently set dark mode as the theme? so no colormode switch and only dark mode available @haughty forum

haughty forumBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

Yes, it is possible to permanently set dark mode as the only available theme in your Nuxt app using Nuxt UI. You can achieve this by:

  1. Forcing dark mode globally:
    In your CSS (e.g., app/assets/css/main.css), you can set the dark mode variables directly:

    :root {
      color-scheme: dark;
    }
    html {
      color-scheme: dark;
    }
    body {
      background: var(--ui-bg, #000);
      color: var(--ui-text, #fff);
    }
    
  2. Disabling color mode switching:
    In your nuxt.config.ts, disable the color mode integration so users cannot switch themes:

    export default defineNuxtConfig({
      modules: ['@nuxt/ui'],
      css: ['~/assets/css/main.css'],
      ui: {
        colorMode: false
      }
    })
    

    This prevents the @nuxtjs/color-mode module from being loaded, so only your custom dark mode styles will apply Nuxt UI Color Mode Docs.

  3. Do not include any color mode switch components (like UColorModeSwitch or UColorModeSelect) in your UI.

With these steps, your app will always use dark mode, and users will not have the option to switch to light mode.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@turbid sun Kapa.ai is still learning and improving, please let me know how I did by reacting below.

turbid sun
#

@haughty forum if i want to enable color mode BUT set the default to dark. how?

haughty forumBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

To enable color mode in your Nuxt app and set the default to dark, you should configure the color mode preference in your nuxt.config.ts:

export default defineNuxtConfig({
  colorMode: {
    preference: 'dark', // Set default theme to dark
  }
})

This will enable color mode switching, but the initial/default mode will be dark. Note that if a user has previously selected a color mode, their preference (stored in localStorage) will take precedence over this default setting Stack Overflow.

If you are using Nuxt UI, it automatically registers the @nuxtjs/color-mode module, so you only need to set the preference as shown above Nuxt UI Color Mode Docs.

Important:

  • Do not disable color mode in the ui config if you want to allow switching.
  • The default will only apply for new users or those without a saved preference.

This setup will allow users to switch between light and dark modes, with dark as the default.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: