#docs template
12 messages · Page 1 of 1 (latest)
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:
-
.env Usage and Build Time
Environment variables from.env(likeNUXT_PUBLIC_SITE_URL) are only loaded at development, build, and generate time. If you update your.envfile, you must restart your dev server or rebuild your project for changes to take effect. In production,.envfiles 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. -
Static Site Generation and OG Images
If you are generating a static site (usingnuxt 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_URLin your.envfile. - Stop your dev/build process.
- Run the build/generate command again.
- Set
-
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 fromuseRuntimeConfig().publicoruseAppConfig()as appropriate. If you are using a static value in yournuxt.config, it will not update unless you rebuild.
-
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 usingnitro.prerender.routesin yournuxt.configNuxt Image Static Images. -
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_URLis set in your.envbefore building. - Restart your dev server or rebuild your project after changing
.env. - For static sites, re-run
nuxi generateafter 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.
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
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:
-
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); } -
Disabling color mode switching:
In yournuxt.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-modemodule from being loaded, so only your custom dark mode styles will apply Nuxt UI Color Mode Docs. -
Do not include any color mode switch components (like
UColorModeSwitchorUColorModeSelect) 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.
@haughty forum if i want to enable color mode BUT set the default to dark. how?
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
uiconfig if you want to allow switching. - The default will only apply for new users or those without a saved preference.