mahee-auffret/nuxt.config.ts

63 lines
1.6 KiB
TypeScript
Raw Normal View History

// nitro hook to get Directus files working on ssg
// https://github.com/codepie-io/nuxt3-dynamic-routes/blob/main/nuxt.config.ts
import { createDirectus, staticToken, rest, readFiles } from '@directus/sdk';
2024-02-21 00:30:14 +01:00
export default defineNuxtConfig({
devtools: { enabled: true },
modules: [
'nuxt-directus',
'@nuxt/image',
'@nuxtjs/seo'
],
runtimeConfig: {
apiURL: process.env.DIRECTUS_URL,
apiToken: process.env.DIRECTUS_API_TOKEN
},
nitro: {
hooks: {
async 'prerender:routes'(routes) {
const client = createDirectus(process.env.DIRECTUS_URL)
.with(staticToken(process.env.DIRECTUS_API_TOKEN))
.with(rest());
const directusFiles = await client.request(
readFiles({
query: {
filter: {
type: {
_eq: 'image',
},
},
},
})
);
for (let image of directusFiles) {
// @TODO: vérifier si le fichier existe pas déjà
// avant de l'ajouter aux routes à prerender
routes.add(`/api/assets/${image.id}.webp`);
}
}
}
},
2024-02-21 00:30:14 +01:00
app: {
pageTransition: { name: 'page', mode: 'out-in' }
},
site: {
url: process.env.URL,
2024-02-21 00:30:14 +01:00
defaultLocale: 'fr',
name: 'Mahée Auffret',
description: 'Portfolio de l\'artiste-peintre basée à Rennes Mahée Auffret'
},
directus: {
url: process.env.DIRECTUS_URL,
2024-02-21 00:30:14 +01:00
token: process.env.DIRECTUS_API_TOKEN
},
image: {
provider: 'ipx',
// domains: [ `${process.env.URL}/api/assets/` ]
2024-02-21 00:30:14 +01:00
}
})