2024-04-06 00:46:44 +02:00
|
|
|
// 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'
|
|
|
|
],
|
2024-04-06 00:46:44 +02:00
|
|
|
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: {
|
2024-02-21 01:21:11 +01:00
|
|
|
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: {
|
2024-02-21 01:21:11 +01:00
|
|
|
url: process.env.DIRECTUS_URL,
|
2024-02-21 00:30:14 +01:00
|
|
|
token: process.env.DIRECTUS_API_TOKEN
|
|
|
|
},
|
|
|
|
image: {
|
2024-04-06 00:46:44 +02:00
|
|
|
provider: 'ipx',
|
|
|
|
// domains: [ `${process.env.URL}/api/assets/` ]
|
2024-02-21 00:30:14 +01:00
|
|
|
}
|
|
|
|
})
|