Skip to content

Commit

Permalink
Add good image for cocktail page
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Sep 26, 2024
1 parent e9165f6 commit c835e12
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
8 changes: 4 additions & 4 deletions features/cocktail/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { buildImages, buildOgImage } = require("../../utils/image");
const { buildImages, buildOgImage, buildGoodsImageInFeed, buildGlasswaresImageInFeed, buildToolsImageInFeed } = require("../../utils/image");
const Database = require('../../database/newclient');
const { getCocktailBySlug } = require("../../database/cocktail");

Expand Down Expand Up @@ -56,23 +56,23 @@ async function getFullCocktailBySlug(slug) {
name: good.name,
amount: good.amount,
unit: good.unit,
images: buildImages(good.id, 'ITEM')
images: buildGoodsImageInFeed(good.slug)
}));

const glassware = cocktail.glassware.map(glass => ({
id: glass.id,
slug: glass.slug,
url: `glassware/${glass.slug}`,
name: glass.name,
images: buildImages(glass.id, 'ITEM')
images: buildGlasswaresImageInFeed(glass.slug)
}));

const tools = cocktail.tools.map(tool => ({
id: tool.id,
slug: tool.slug,
url: `tools/${tool.slug}`,
name: tool.name,
images: buildImages(tool.id, 'ITEM')
images: buildToolsImageInFeed(tool.slug)
}));

const taste = cocktail.tastes.map(taste => ({
Expand Down
48 changes: 48 additions & 0 deletions utils/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,51 @@ const buildGlasswareDetailsImage = (slug) => {
);
}

const buildGoodsImageInFeed = (slug) => {
const sizes = [
{ responseSize: "414px", imageSize: "142" },
{ responseSize: "0", imageSize: "100" }
];

return formats.flatMap(format =>
sizes.map(size => ({
srcset: `${imageUrlStart}/v2/goods/${slug}/${size.imageSize}.${format}`,
media: `screen and (min-width: ${size.responseSize})`,
type: `image/${format}`
}))
);
}

const buildToolsImageInFeed = (slug) => {
const sizes = [
{ responseSize: "414px", imageSize: "142" },
{ responseSize: "0", imageSize: "100" }
];

return formats.flatMap(format =>
sizes.map(size => ({
srcset: `${imageUrlStart}/v2/tools/${slug}/${size.imageSize}.${format}`,
media: `screen and (min-width: ${size.responseSize})`,
type: `image/${format}`
}))
);
}

const buildGlasswaresImageInFeed = (slug) => {
const sizes = [
{ responseSize: "414px", imageSize: "142" },
{ responseSize: "0", imageSize: "100" }
];

return formats.flatMap(format =>
sizes.map(size => ({
srcset: `${imageUrlStart}/v2/glasswares/${slug}/${size.imageSize}.${format}`,
media: `screen and (min-width: ${size.responseSize})`,
type: `image/${format}`
}))
);
}

module.exports = {
buildImages,
buildOgImage,
Expand All @@ -119,4 +164,7 @@ module.exports = {
buildGoodDetailsImage,
buildToolDetailsImage,
buildGlasswareDetailsImage,
buildGoodsImageInFeed,
buildToolsImageInFeed,
buildGlasswaresImageInFeed,
}

0 comments on commit c835e12

Please sign in to comment.