Skip to content

Commit

Permalink
Improve generation of icon preview images
Browse files Browse the repository at this point in the history
  • Loading branch information
PKief committed Jul 1, 2021
1 parent bd77a62 commit cd91ac4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/scripts/preview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ const folderThemes = filterDuplicates(

generatePreview('fileIcons', basicFileIcons, 5, [
'virtual',
// 'powerpoint',
// 'word',
// 'credits',
'powerpoint',
'word',
'credits',
]);
generatePreview('folderIcons', folderThemes, 5, [
'folder-aurelia',
'folder-phpmailer',
'folder-syntax',
'folder-ansible',
]);
38 changes: 31 additions & 7 deletions src/scripts/preview/preview.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as fs from 'fs';
import * as path from 'path';
import { toTitleCase } from './../helpers/titleCase';
import { createScreenshot } from '../helpers/screenshots';
import * as painter from './../helpers/painter';
import { toTitleCase } from './../helpers/titleCase';

const htmlDoctype = '<!DOCTYPE html>';
const cssFilePath = path.join('style.css');
Expand Down Expand Up @@ -94,9 +94,8 @@ const getIconDefinitionsMatrix = (
size: number,
excluded: string[] = []
): IconDefinition[][] => {
const iconList = icons
.sort((a, b) => a.label.localeCompare(b.label))
.filter((i) => excluded.indexOf(i.iconName) === -1);
const iconList = icons.sort((a, b) => a.label.localeCompare(b.label));
trimIconListToSize(iconList, size, excluded);

// list for the columns with the icons
const matrix: IconDefinition[][] = [];
Expand Down Expand Up @@ -124,18 +123,43 @@ const getIconDefinitionsMatrix = (
* @param name name of the preview
* @param icons icons for the preview
* @param size amount of table columns
* @param excluded which icons shall be excluded
* @param trimmableIcons List of icons that can possibly be trimmed
*/
export const generatePreview = (
name: string,
icons: IconDefinition[],
size: number,
excluded: string[] = []
trimmableIcons: string[] = []
) => {
savePreview(name, size, getIconDefinitionsMatrix(icons, size, excluded));
savePreview(
name,
size,
getIconDefinitionsMatrix(icons, size, trimmableIcons)
);
};

interface IconDefinition {
iconName: string;
label: string;
}

/**
* Trim the list of icons into the matrix
* @param iconList List of icons
* @param size Amount of columns
* @param trimmableIcons List of icons that can possibly be trimmed
*/
const trimIconListToSize = (
iconList: IconDefinition[],
size: number,
trimmableIcons: string[]
) => {
while (iconList.length % size !== 0) {
iconList.splice(
iconList.findIndex(
(i) => i.iconName === trimmableIcons[iconList.length % size]
),
1
);
}
};

0 comments on commit cd91ac4

Please sign in to comment.