You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.8 KiB
44 lines
1.8 KiB
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)];
|
|
}
|
|
}
|