Skip to content

Commit

Permalink
optimized filename for aspectRatio images
Browse files Browse the repository at this point in the history
  • Loading branch information
friewerts committed Feb 22, 2020
1 parent 0a44d26 commit 3ca7dc9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ interface RenditionOptions extends Rendition {
dirname: string;
}

const getFilename = (renditionOptions: Rendition, image: ImageOptions): string => {
const base = `${image.filename}__${renditionOptions.width}`;
if (renditionOptions.height) return `${base}x${renditionOptions.height}`;
return base;
};

const hasAspectRatio = (options: Rendition): boolean => {
if (options.aspectRatio === undefined) return false;
const aspectParts = options.aspectRatio.split(':');
Expand All @@ -48,6 +42,13 @@ const hasAspectRatio = (options: Rendition): boolean => {
return true;
};

const getFilename = (renditionOptions: Rendition, image: ImageOptions): string => {
const base = `${image.filename}__${renditionOptions.width}`;
if (hasAspectRatio(renditionOptions)) return `${base}_${renditionOptions.aspectRatio?.split(':').join('x')}`;
else if (renditionOptions.height) return `${base}x${renditionOptions.height}`;
return base;
};

const getHeight = (aspectRatio: string, width: number): number => {
const aspectParts = aspectRatio.split(':');

Expand Down

0 comments on commit 3ca7dc9

Please sign in to comment.