Skip to content

DX improvements #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: vue3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ Statamic adapter for [@teamnovu/nuxt-cloudinary-image](https://github.com/teamno

## Features
✅ Handles Statamic Image Assets
✅ Automatically applies `alt` attribute
✅ Automatically applies `alt` attribute for the current locale *
✅ Automatically applies Statamic focal point

* For the i18n support, `alt_{langcode}` fields are assumed on asset blueprint and data. It will fallback to `alt` if not available.

## Prerequisites

Install and configure either [@teamnovu/nuxt-cloudinary-image](https://github.com/teamnovu/nuxt-cloudinary-image) or [@teamnovu/vue-cloudinary-image](https://github.com/teamnovu/vue-cloudinary-image) first. Visit these projects for instructions.

Make sure the asset includes `width`, `height` and `focus` data.
Make sure the asset includes `width`, `height`, `focus` and the different `alt_{langcode}` data.

Example Statamic `CustomAsset`:
```php
Expand All @@ -25,7 +27,7 @@ class CustomAsset extends Asset
{
protected function shallowAugmentedArrayKeys()
{
return ['id', 'url', 'permalink', 'api_url', 'extension', 'is_image', 'focus', 'width', 'height'];
return ['id', 'url', 'permalink', 'api_url', 'extension', 'is_image', 'focus', 'width', 'height', 'alt_de', 'alt_fr'];
}
}
```
Expand All @@ -42,7 +44,8 @@ Example Statamic GraphQL fragment:
width
height
... on Asset_Assets {
alt
alt_de
alt_fr
}
}
```
Expand Down
13 changes: 11 additions & 2 deletions src/AppImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
props: {
src: {
type: [String, Object],
required: true,
required: false,
},

alt: {
Expand Down Expand Up @@ -62,7 +62,16 @@ export default {
},

assetAlt () {
return this.alt || this.asset.alt || ''
if (this.alt) {
return this.alt
}

const locale = this.$i18n?.locale
if (this.asset[`alt_${locale}`]) {
return this.asset[`alt_${locale}`]
}

return this.asset.alt ?? undefined
},

imageFocus () {
Expand Down