Skip to content

Commit

Permalink
Update OS listing .json files
Browse files Browse the repository at this point in the history
  • Loading branch information
relliv committed Jan 26, 2022
1 parent 6121cd5 commit e00da2c
Show file tree
Hide file tree
Showing 4 changed files with 457 additions and 6 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ npm i @egoistdeveloper/operating-system-logos
- 64x64
- 128x128

## List of operating system names and custom short codes
Image files are named according to these titles (*see the **[reference](https://github.com/matomo-org/device-detector/blob/228eef9a40f611a6661f1c93ee64c2c687dd3f11/Parser/OperatingSystem.php#L40)***). Current and frequently used logos defining operating systems were selected. Therefore, the version or naming differences were ignored when listing.
## List of operating system names and short codes

Image files are named according to these name (*see the **[reference](https://github.com/matomo-org/device-detector/blob/228eef9a40f611a6661f1c93ee64c2c687dd3f11/Parser/OperatingSystem.php#L40)***). Current and frequently used logos defining operating systems were selected. Therefore, the version or naming differences were ignored when listing.

There is no standard or formula for OS cataloging. This project uses above referenced alpha3 codes and generic names. There are many solution for OS name showing and we can use below listing methods. We can search in `slug/name` list then use matched result code for showing os icon file (yes, I know it is not the best way. we can discuss).

Alpha3 list [alpha3-list.json](./src/alpha3-list.json) and slug list [slug-list.json](./src/os-list.json).


## Preview List

Expand Down
File renamed without changes.
36 changes: 32 additions & 4 deletions src/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const sizeList = [16, 24, 32, 48, 64, 128],
baseRepoAddress = 'https://raw.githubusercontent.com/EgoistDeveloper/operating-system-logos/master',
previewSize = '48x48';

/**
* Update readme preview list
*
* @param {string} newData
*/
function updateList(newData) {
fs.readFile('./../README.md', 'utf8', (err, data) => {
if (err) {
Expand All @@ -34,10 +39,23 @@ function updateList(newData) {
});
}

function copyWithSlug(osCode, osName) {
const slug = osName.toLowerCase().replace(/ /g,'-').replace(/[-]+/g, '-').replace(/[^\w-]+/g,'');

const slugItem = {
code: osCode,
name: osName,
slug: slug
};

return slugItem;
}

try {
let osList = JSON.parse(fs.readFileSync('list.json')),
let osList = JSON.parse(fs.readFileSync('alpha3-list.json')),
tableMarkdown = `| Preview | Code | Name | Status |\n| ------- | ---- | ---- | ------ |\n`,
availableItems = 0;
availableItems = 0,
slugList = [];

osList = Object.entries(osList);

Expand All @@ -64,15 +82,17 @@ try {
if (logoStackCount == 0) {
tableMarkdown += `| ............ | ${osCode} | ${osName} | ❌ |\n`;

// console.log(`❌ ${osName} (${osCode}): all logos not found.\n--------------------------`);
console.log(`❌ ${osName} (${osCode}): all logos not found.\n--------------------------`);
} else if (logoStackCount == sizeList.length) {
tableMarkdown += `| ![](${baseRepoAddress}/src/${previewSize}/${osCode}.png "${osCode} (${previewSize})") | ${osCode} | ${osName} | ✅ |\n`;

slugList.push(copyWithSlug(osCode, osName));

availableItems += 1;
} else if (logoStackCount > 0 && logoStackCount < sizeList.length) {
tableMarkdown += `| ............ | ${osCode} | ${osName} | ⭕ |\n`;

// console.log(`⭕ ${osName} (${osCode}): ${sizeList.length - logoStackCount} logos missing (sizes: ${missingSizes.join(', ')})\n--------------------------`);
console.log(`⭕ ${osName} (${osCode}): ${sizeList.length - logoStackCount} logos missing (sizes: ${missingSizes.join(', ')})\n--------------------------`);
}

//#endregion
Expand All @@ -83,6 +103,14 @@ try {
console.log(`\n${totalStatistics}\n\n`);

updateList(`${totalStatistics}\n\n${tableMarkdown}`);

if (slugList) {
fs.writeFile('./os-list.json', JSON.stringify(slugList, null, 2), function (err) {
if (err) throw err;

console.log('slug-list.json updated!');
});
}
} catch (err) {
console.log(err.toString());
}
Loading

0 comments on commit e00da2c

Please sign in to comment.