Skip to content

Commit

Permalink
feat: create static build URL and srcset methods
Browse files Browse the repository at this point in the history
  • Loading branch information
luqven committed Mar 10, 2022
1 parent a8c31a5 commit 0df05b2
Showing 1 changed file with 41 additions and 5 deletions.
46 changes: 41 additions & 5 deletions src/plugins/vue-imgix/vue-imgix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class VueImgixClient implements IVueImgixClient {
...sharedOptions // Right now this is only passed to buildSrcSet, but in the future it might be passed to buildUrl
} = options;

const src = this.buildUrl(url, ixParams);
const srcset = this.buildSrcSet(url, ixParams, {
const src = this._buildUrl(url, ixParams);
const srcset = this._buildSrcSet(url, ixParams, {
widths,
widthTolerance,
minWidth,
Expand All @@ -73,12 +73,48 @@ class VueImgixClient implements IVueImgixClient {
return this.client.buildURL(url, this.buildIxParams(ixParams));
};

_buildUrl = (url: string, ixParams?: IImgixParams): string => {
// if 2-step URL
if (!url.includes('://')) {
return this.client.buildURL(url, this.buildIxParams(ixParams));
} else {
return ImgixClient._buildURL({ url, params: this.buildIxParams(ixParams) });
}

};

buildSrcSet = (
url: string,
ixParams?: IImgixParams,
options?: IBuildSrcSetOptions,
): string => {
return this.client.buildSrcSet(url, this.buildIxParams(ixParams), options);
return this.client.buildSrcSet(
url,
this.buildIxParams(ixParams),
options,
);
};

_buildSrcSet = (
url: string,
ixParams?: IImgixParams,
options?: IBuildSrcSetOptions,
): string => {
// if 2-step URL
// eslint-disable-next-line
if (!url.includes('://')) {
return this.client.buildSrcSet(
url,
this.buildIxParams(ixParams),
options,
);
} else {
return ImgixClient._buildSrcSet({
url,
params: this.buildIxParams(ixParams),
options,
});
}
};
}

Expand Down Expand Up @@ -112,12 +148,12 @@ export const buildUrlObject: IBuildUrlObject = (...args) => {

export const buildUrl: IBuildUrl = (...args) => {
const client = ensureVueImgixClientSingleton();
return client.buildUrl(...args);
return client._buildUrl(...args);
};

export const buildSrcSet: IBuildSrcSet = (...args) => {
const client = ensureVueImgixClientSingleton();
return client.buildSrcSet(...args);
return client._buildSrcSet(...args);
};

export { IVueImgixClient, IxImg };

0 comments on commit 0df05b2

Please sign in to comment.