Replies: 2 comments
-
Also looking for something like this. I'm building a documentation and have quite some code per md file to render. Now I have to store all of this in my public folder, and that feels odd... Already found something? |
Beta Was this translation helpful? Give feedback.
-
There's two ways I have found to handle this, we can use the vite-plugin-static-copy plugin or use If you have the following folder structure
You can update your import { fileURLToPath } from 'node:url'
import { viteStaticCopy } from 'vite-plugin-static-copy'
export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
devtools: { enabled: true },
modules: ['@nuxt/content'],
vite: {
plugins: [
viteStaticCopy({
targets: [
{
src: fileURLToPath(new URL('content/blog/**/.meta/**/*.{png,jpg}', import.meta.url)),
dest: fileURLToPath(new URL('public/imgs', import.meta.url))
}
]
})
]
}
}) This will output
and you can reference the files like this in the markdown file # post 1
 The other method is to statically serve the assets with nitro. import fg from 'fast-glob'
import { fileURLToPath } from 'node:url'
export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
devtools: { enabled: true },
modules: ['@nuxt/content'],
hooks: {
async 'nitro:config'(nitroConfig) {
const dirs = await fg('content/blog/**/.meta/imgs/**', {
dot: true,
onlyDirectories: true
})
for (const dir of dirs) {
nitroConfig.publicAssets?.push({
baseURL: '/',
dir: fileURLToPath(new URL(dir, import.meta.url)),
maxAge: 60 * 60 * 24 * 7
})
}
}
}
}) You can then reference the images in the markdown file as: # first post
 If you wanted to change it so that you reference an image as import fg from 'fast-glob'
import { fileURLToPath } from 'node:url'
export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
devtools: { enabled: true },
modules: ['@nuxt/content'],
hooks: {
async 'nitro:config'(nitroConfig) {
const dirs = await fg('content/blog/**/.meta/imgs/**', {
dot: true,
onlyDirectories: true
})
for (const dir of dirs) {
nitroConfig.publicAssets?.push({
- baseURL: '/',
+ baseURL: '/imgs',
dir: fileURLToPath(new URL(dir, import.meta.url)),
maxAge: 60 * 60 * 24 * 7
})
}
}
}
}) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I‘m not sure if there is a way to do this but it would come in handy. Say we have colocated files for our blog posts:
it would be super useful if we could reference an image in our blog like this
Beta Was this translation helpful? Give feedback.
All reactions