Created
January 25, 2022 11:27
-
-
Save touhidrahman/7f3422f2a11d538d4ba2d1d0ba765cd3 to your computer and use it in GitHub Desktop.
Sanity Image URL generator
This file contains hidden or 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
| import { Pipe, PipeTransform } from '@angular/core' | |
| import { SanityService } from '@core/services/sanity.service' | |
| import { SanityImageSource } from '@sanity/image-url/lib/types/types' | |
| @Pipe({ name: 'sanityImage' }) | |
| export class SanityImagePipe implements PipeTransform { | |
| constructor(private sanityService: SanityService) {} | |
| transform(value: SanityImageSource, width?: number): string { | |
| if (width) { | |
| return this.sanityService.getImageUrlBuilder(value).width(width).url() | |
| } | |
| return this.sanityService.getImageUrlBuilder(value).url() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment