parent
5315b6a5ac
commit
8c28b6e25a
@ -0,0 +1,43 @@
|
|||||||
|
import delve from 'dlv';
|
||||||
|
|
||||||
|
import {environment} from "../environments/environment";
|
||||||
|
|
||||||
|
export type ImageFormatType = "default" | "thumbnail" | "medium" | "small";
|
||||||
|
|
||||||
|
export const getCategoryUrl = (item): string => {
|
||||||
|
return '/blog/' + delve(item, 'attributes.category.data.attributes.slug', '');
|
||||||
|
}
|
||||||
|
export const getPostUrl = (item): string => {
|
||||||
|
return '/blog/' + getCategoryUrl(item) + '/' + delve(item, 'attributes.slug', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getStrapiImage = (item, format: ImageFormatType = 'default') => {
|
||||||
|
const image = delve(item, 'attributes.image.data.attributes', {});
|
||||||
|
switch (format) {
|
||||||
|
case "default":
|
||||||
|
return environment.strapiUrl + delve(image, "url", "/images/default.png");
|
||||||
|
case "medium":
|
||||||
|
return environment.strapiUrl + delve(image, "formats.medium.url", "/images/default.png");
|
||||||
|
case "small":
|
||||||
|
return environment.strapiUrl + delve(image, "formats.small.url", "/images/default.png");
|
||||||
|
case "thumbnail":
|
||||||
|
return environment.strapiUrl + delve(image, "formats.thumbnail.url", "/images/default.png");
|
||||||
|
default:
|
||||||
|
return environment.strapiUrl + delve(image, "url", "/images/default.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const getStrapiImageSize = (item, format: ImageFormatType = 'default'): [number, number] => {
|
||||||
|
const image = delve(item, 'attributes.image.data.attributes', {});
|
||||||
|
switch (format) {
|
||||||
|
case "default":
|
||||||
|
return [delve(image, "width", 100), delve(image, "height", 100)];
|
||||||
|
case "medium":
|
||||||
|
return [delve(image, "formats.medium.width", 100), delve(image, "formats.medium.height", 100)];
|
||||||
|
case "small":
|
||||||
|
return [delve(image, "formats.small.width", 100), delve(image, "formats.small.height", 100)];
|
||||||
|
case "thumbnail":
|
||||||
|
return [delve(image, "formats.thumbnail.width", 100), delve(image, "formats.thumbnail.height", 100)];
|
||||||
|
default:
|
||||||
|
return [delve(image, "width", 100), delve(image, "height", 100)];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue