-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# What 💻 * Install the Nuxt Image module # Why ✋ * Optimizes images # Notes 📝 * Nuxt Content just added NuxtImage support in their `ProseImg` component literally hours ago. This means that it is not available yet in an official release. In the meantime, I just copied the code from the PR and we can remove our `ProseImg` component when the latest release includes it.
- Loading branch information
1 parent
4c94b3d
commit 18fee59
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<template> | ||
<component | ||
:is="imgComponent" | ||
:src="refinedSrc" | ||
:alt="alt" | ||
:width="width" | ||
:height="height" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
/** | ||
* This is a temporary component until the Nuxt Content release includes these changes | ||
*/ | ||
import { withTrailingSlash, withLeadingSlash, joinURL } from 'ufo'; | ||
import { useRuntimeConfig, computed, resolveComponent } from '#imports'; | ||
const imgComponent = useRuntimeConfig().public.mdc.useNuxtImage ? resolveComponent('NuxtImg') : 'img'; | ||
const props = defineProps({ | ||
src: { | ||
type: String, | ||
default: '', | ||
}, | ||
alt: { | ||
type: String, | ||
default: '', | ||
}, | ||
width: { | ||
type: [String, Number], | ||
default: undefined, | ||
}, | ||
height: { | ||
type: [String, Number], | ||
default: undefined, | ||
}, | ||
}); | ||
const refinedSrc = computed(() => { | ||
if (props.src?.startsWith('/') && !props.src.startsWith('//')) { | ||
const _base = withLeadingSlash(withTrailingSlash(useRuntimeConfig().app.baseURL)); | ||
if (_base !== '/' && !props.src.startsWith(_base)) { | ||
return joinURL(_base, props.src); | ||
} | ||
} | ||
return props.src; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters