Skip to content

Commit

Permalink
feat: support diff image ext (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
bokuweb authored Aug 18, 2024
1 parent 9198450 commit c50b0f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/states/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ export const initializeEntityState = (
actual: data.actualDir,
};

const diffExtension = data.diffImageExtension ?? 'png';

store.set(defaultEntityAtom, {
new: toEntities('new', dirs, data.newItems),
passed: toEntities('passed', dirs, data.passedItems),
failed: toEntities('changed', dirs, data.failedItems),
deleted: toEntities('deleted', dirs, data.deletedItems),
new: toEntities('new', dirs, data.newItems, diffExtension),
passed: toEntities('passed', dirs, data.passedItems, diffExtension),
failed: toEntities('changed', dirs, data.failedItems, diffExtension),
deleted: toEntities('deleted', dirs, data.deletedItems, diffExtension),
});

const defaultEntity = store.get(defaultEntityAtom);
Expand Down
1 change: 1 addition & 0 deletions src/types/reg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type RegData = {
deletedItems: RegItem[];
ximgdiffConfig?: XIMGDiffConfig;
links?: RegLink[];
diffImageExtension?: 'webp' | 'png';
};

export type RegEntity = {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const toEntities = (
variant: RegVariant,
dirs: Dirs,
items: RegItem[],
diffExtension: 'png' | 'webp' = 'png',
): RegEntity[] => {
const join = (key: keyof Dirs, to: string) =>
dirs[key].replace(/\/$/, '') + '/' + to.replace(/^\//, '');
Expand All @@ -26,7 +27,7 @@ export const toEntities = (
id,
variant,
name: item.raw,
diff: join('diff', item.encoded).replace(/\.[^.]+$/, '.png'),
diff: join('diff', item.encoded).replace(/\.[^.]+$/, `.${diffExtension}`),
before: join('expected', item.encoded),
after: join('actual', item.encoded),
};
Expand Down

0 comments on commit c50b0f9

Please sign in to comment.