1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2025-07-12 22:21:23 +02:00

Fix 3rd party extensions order, add test to avoid regression (#7111)

* Fix 3rd party extensions order and add test to avoid regression

* Prevent possible error in test

* Apply suggestions from code review

* Apply suggestion

* Remove uneeded import
This commit is contained in:
Álvaro Mondéjar
2022-01-30 23:09:44 +01:00
committed by GitHub
parent 6e42629956
commit 6be07af824
4 changed files with 93 additions and 44 deletions

View File

@ -97,7 +97,7 @@ export const htmlFriendlyToTitle = (htmlFriendlyTitle) =>
* Get contents of _data/simple-icons.json.
*/
export const getIconsDataString = () => {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const __dirname = getDirnameFromImportMeta(import.meta.url);
const rootDir = path.resolve(__dirname, '..');
const iconDataPath = path.resolve(rootDir, '_data', 'simple-icons.json');
return fs.readFile(iconDataPath, 'utf8');
@ -117,3 +117,30 @@ export const getIconsData = async () => {
*/
export const getDirnameFromImportMeta = (importMetaUrl) =>
path.dirname(fileURLToPath(importMetaUrl));
/**
* Get information about third party extensions.
*/
export const getThirdPartyExtensions = async () => {
const __dirname = getDirnameFromImportMeta(import.meta.url);
const readmePath = path.resolve(__dirname, '..', 'README.md');
const readmeContent = await fs.readFile(readmePath, 'utf8');
return readmeContent
.split('## Third-Party Extensions\n\n')[1]
.split('\n\n')[0]
.split('\n')
.slice(2)
.map((line) => {
const [module, author] = line.split(' | ');
return {
module: {
name: /\[(.+)\]/.exec(module)[1],
url: /\((.+)\)/.exec(module)[1],
},
author: {
name: /\[(.+)\]/.exec(author)[1],
url: /\((.+)\)/.exec(author)[1],
},
};
});
};