From 20ee20654407010bfbe881e3c4760887747aaaae Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 25 Jul 2020 03:57:25 +0800 Subject: [PATCH] Update API Change query params to accommodate other dynamic fields. --- getBadgeUrl.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/getBadgeUrl.js b/getBadgeUrl.js index 8881f3b..8eab875 100644 --- a/getBadgeUrl.js +++ b/getBadgeUrl.js @@ -20,11 +20,14 @@ module.exports = async ({ let badgeUrl switch (type) { - case 'version': + case 'package': + if (!['name', 'version'].includes(kind)) { + return null + } badgeUrl = new URL(`/badge/dynamic/json`, process.env.SHIELDS_IMAGE_BASE_URL) badgeUrl.search = new URLSearchParams({ color, - query: '$.version', + query: `$.${kind}`, label: repo, style, labelColor, @@ -32,6 +35,9 @@ module.exports = async ({ }).toString() return badgeUrl case 'dependency': + if (!['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'].includes(kind)) { + return null + } const brands = await loadBrands() const libraryInfo = getLibraryColor(library, brands, RESOLVE) const libraryColor = libraryInfo ? libraryInfo.color.replace('#', '') : `${labelColor}`