Skip to content

Commit

Permalink
Revisit nuxt img (#80)
Browse files Browse the repository at this point in the history
* update to latest vue use and add missing package

* add nuxt img

* swap directus image comp

* remove commented out bits
  • Loading branch information
bryantgillespie authored Oct 6, 2023
1 parent 8bb55ca commit 9904f78
Show file tree
Hide file tree
Showing 4 changed files with 448 additions and 396 deletions.
22 changes: 2 additions & 20 deletions components/Base/DirectusImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,9 @@ export interface DirectusImageProps {
height?: number;
}
const props = defineProps<DirectusImageProps>();
const { pixelRatio } = useDevicePixelRatio();
const src = computed(() => {
const url = new URL(`/assets/${props.uuid}`, directusUrl);
url.searchParams.set('format', 'auto');
if (props.width) {
url.searchParams.set('width', String(Math.round(props.width * unref(pixelRatio))));
}
if (props.height) {
url.searchParams.set('height', String(Math.round(props.height * unref(pixelRatio))));
}
return url.toString();
});
defineProps<DirectusImageProps>();
</script>

<template>
<img :src="src" :alt="alt" :width="width" :height="height" loading="lazy" />
<NuxtImg :src="uuid" :alt="alt" :width="width" :height="height" format="auto" loading="lazy" />
</template>
9 changes: 9 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default defineNuxtConfig({

modules: [
'@vueuse/nuxt',
'@nuxt/image',
'nuxt-simple-sitemap', // https://nuxtseo.com/sitemap/getting-started/how-it-works
'nuxt-og-image',
'floating-vue/nuxt',
Expand All @@ -113,6 +114,14 @@ export default defineNuxtConfig({
fonts: ['Inter:400', 'Inter:700', 'Poppins:400', 'Poppins:600', 'Poppins:700'],
},

// Nuxt Image Configuration - https://image.nuxtjs.org/getting-started/installation
image: {
provider: 'directus',
directus: {
baseURL: `${process.env.DIRECTUS_URL}/assets/`,
},
},

vite: {
vue: {
script: {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"@types/node": "20.2.5",
"@typescript-eslint/eslint-plugin": "5.59.9",
"@typescript-eslint/parser": "5.59.9",
"@vueuse/nuxt": "10.2.1",
"@vueuse/core": "10.4.1",
"@vueuse/nuxt": "10.4.1",
"@zadigetvoltaire/nuxt-gtm": "0.0.13",
"eslint": "8.42.0",
"eslint-config-prettier": "8.8.0",
Expand All @@ -39,6 +40,7 @@
"pnpm": ">=8.6.0"
},
"dependencies": {
"@nuxt/image": "1.0.0-rc.3",
"floating-vue": "2.0.0-beta.24",
"p-queue": "7.3.4"
}
Expand Down
Loading

0 comments on commit 9904f78

Please sign in to comment.