handle plugin icon

This commit is contained in:
Jan Prochazka
2022-04-03 13:13:27 +02:00
parent 5ea6c56752
commit 9f5013c6da
2 changed files with 23 additions and 8 deletions

View File

@@ -6,17 +6,24 @@ export function extractPluginIcon(packageManifest) {
const homepage = (links && links.homepage) || packageManifest.homepage;
const tested = repository || homepage || packageManifest.homepage;
if (packageManifest.description) {
const iconLink = packageManifest.description.match(/\!\[icon\]\(([^)]+)\)/, '');
if (iconLink) {
return iconLink[1];
}
}
if (tested == 'https://dbgate.org' || tested == 'https://github.com/dbgate/dbgate') {
// monorepo plugin
return `https://github.com/dbgate/dbgate/raw/master/plugins/${packageManifest.name}/icon.svg`;
}
if (tested) {
const match = tested.match(/https:\/\/github.com\/([^/]*)\/([^/]*)/);
if (match) {
return `https://raw.githubusercontent.com/${match[1]}/${match[2]}/master/icon.svg`;
}
}
// if (tested) {
// const match = tested.match(/https:\/\/github.com\/([^/]*)\/([^/]*)/);
// if (match) {
// return `https://raw.githubusercontent.com/${match[1]}/${match[2]}/master/icon.svg`;
// }
// }
return 'unknown.svg';
}
@@ -39,3 +46,11 @@ export function extractPluginAuthor(packageManifest) {
}
return '(Unknown author)';
}
export function extractPluginDescription(packageManifest) {
if (!packageManifest.description || packageManifest.description?.indexOf('[![') >= 0) {
return '(No description)';
}
return packageManifest.description.replace(/\!\[icon\]\([^)]+\)/, '').trim();
}