From f1789d90080c4151104408a4b9c88ac384bb9ee5 Mon Sep 17 00:00:00 2001 From: tandpfun Date: Sat, 5 Mar 2022 09:55:06 -0800 Subject: [PATCH] better shortname handling --- .gitignore | 3 +++ index.js | 42 ++++++++++++------------------------------ worker/script.js | 1 - 3 files changed, 15 insertions(+), 31 deletions(-) delete mode 100644 worker/script.js diff --git a/.gitignore b/.gitignore index 20b0c921..8b0d5b29 100644 --- a/.gitignore +++ b/.gitignore @@ -125,3 +125,6 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* + +# Cloudflare Worker +worker/ \ No newline at end of file diff --git a/index.js b/index.js index a709d05e..b19583fb 100644 --- a/index.js +++ b/index.js @@ -1,43 +1,21 @@ const icons = require("./dist/icons.json"); -const longNames = { +const iconNameList = Object.keys(icons).map((i) => i.split("-")[0]); +const shortNames = { js: "javascript", ts: "typescript", - nodejs: "nodejs", py: "python", - html: "html", - css: "css", tailwind: "tailwindcss", vue: "vuejs", nuxt: "nuxtjs", - prisma: "prisma", - docker: "docker", - figma: "figma", go: "golang", - rust: "rust", - react: "react", - cloudflare: "cloudflare", - java: "java", - php: "php", - ruby: "ruby", + cf: "cloudflare", cs: "C#", cpp: "c++", c: "c", - swift: "swift", - kotlin: "kotlin", - dart: "dart", wasm: "webassembly", - mysql: "mysql", postgres: "postgresql", - redis: "redis", - jquery: "jquery", - angular: "angular", - svelte: "svelte", - git: "git", k8s: "kubernetes", - deno: "deno", - vim: "vim", }; - const themedIcons = [ "nodejs", "python", @@ -88,11 +66,15 @@ function generateSvg(iconNames) { } function parseShortNames(names, theme = "dark") { - return names.map( - (name) => - longNames[name] + - (themedIcons.includes(longNames[name]) ? `-${theme}` : "") - ); + return names.map((name) => { + if (iconNameList.includes(name)) + return name + (themedIcons.includes(name) ? `-${theme}` : ""); + else if (name in shortNames) + return ( + shortNames[name] + + (themedIcons.includes(shortNames[name]) ? `-${theme}` : "") + ); + }); } async function handleRequest(request) { diff --git a/worker/script.js b/worker/script.js deleted file mode 100644 index dc93997c..00000000 --- a/worker/script.js +++ /dev/null @@ -1 +0,0 @@ -!function(C){var t={};function n(i){if(t[i])return t[i].exports;var e=t[i]={i:i,l:!1,exports:{}};return C[i].call(e.exports,e,e.exports,n),e.l=!0,e.exports}n.m=C,n.c=t,n.d=function(C,t,i){n.o(C,t)||Object.defineProperty(C,t,{enumerable:!0,get:i})},n.r=function(C){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(C,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(C,"__esModule",{value:!0})},n.t=function(C,t){if(1&t&&(C=n(C)),8&t)return C;if(4&t&&"object"==typeof C&&C&&C.__esModule)return C;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:C}),2&t&&"string"!=typeof C)for(var e in C)n.d(i,e,function(t){return C[t]}.bind(null,e));return i},n.n=function(C){var t=C&&C.__esModule?function(){return C.default}:function(){return C};return n.d(t,"a",t),t},n.o=function(C,t){return Object.prototype.hasOwnProperty.call(C,t)},n.p="",n(n.s=0)}([function(C,t,n){const i=n(1),e={js:"javascript",ts:"typescript",nodejs:"nodejs",py:"python",html:"html",css:"css",tailwind:"tailwindcss",vue:"vuejs",nuxt:"nuxtjs",prisma:"prisma",docker:"docker",figma:"figma",go:"golang",rust:"rust",react:"react",cloudflare:"cloudflare",java:"java",php:"php",ruby:"ruby",cs:"C#",cpp:"c++",c:"c",swift:"swift",kotlin:"kotlin",dart:"dart",wasm:"webassembly",mysql:"mysql",postgres:"postgresql",redis:"redis",jquery:"jquery",angular:"angular",svelte:"svelte",git:"git",k8s:"kubernetes",deno:"deno",vim:"vim"},l=["nodejs","python","tailwindcss","vuejs","nuxtjs","figma","react","cloudflare","java","php","kotlin","dart","mysql","postgresql","redis","angular","deno","vim"];async function o(C){const{pathname:t,searchParams:n}=new URL(C.url),o=t.split("/")[1];if(!o)return Response.redirect("https://github.com/tandpfun/skill-icons",301);if("icons"===o||"icons.svg"===o){const C=n.get("i")||n.get("icons");if(!C)return new Response("No icons specified",{status:400});const t=n.get("t")||n.get("theme");if(t&&"dark"!==t&&"light"!==t)return new Response("Invalid theme param",{status:400});const o=function(C,t="dark"){return C.map(C=>e[C]+(l.includes(e[C])?"-"+t:""))}(C.split(","),t||void 0);if(!o)return new Response("Invalid icon params",{status:400});const L=function(C){const t=C.map(C=>i[C]),n=300*Math.ceil(t.length/15)-44;return`\n \n ${t.map((C,t)=>`\n \n ${C}\n \n `).join(" ")}\n \n `}(o);return new Response(L,{headers:{"Content-Type":"image/svg+xml"}})}return new Response("404: Not Found",{status:404})}addEventListener("fetch",C=>{C.respondWith(o(C.request).catch(C=>new Response(C.stack,{status:500})))})},function(C){C.exports=JSON.parse('{"angular-dark":"\\n\\n\\n\\n\\n\\n","angular-light":"\\n\\n\\n\\n\\n\\n","c#":"\\n\\n\\n\\n\\n","c++":"\\n\\n\\n\\n\\n\\n","c":"\\n\\n\\n\\n","cloudflare-dark":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","cloudflare-light":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","css":"\\n\\n\\n\\n\\n\\n\\n","dart-dark":"\\n\\n\\n\\n\\n\\n\\n\\n\\n","dart-light":"\\n\\n\\n\\n\\n\\n\\n\\n\\n","deno-dark":"\\n\\n\\n\\n\\n","deno-light":"\\n\\n\\n\\n\\n","docker":"\\n\\n\\n\\n","figma-dark":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","figma-light":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","git":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","golang":"\\n\\n\\n\\n\\n\\n\\n\\n","html":"\\n\\n\\n\\n\\n\\n","java-dark":"\\n\\n\\n\\n\\n","java-light":"\\n\\n\\n\\n\\n","javascript":"\\n\\n\\n\\n\\n","jquery":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","kotlin-dark":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","kotlin-light":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","kubernetes":"\\n\\n\\n\\n","mysql-dark":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","mysql-light":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","nodejs-dark":"\\n\\n\\n\\n\\n","nodejs-light":"\\n\\n\\n\\n\\n","nuxtjs-dark":"\\n\\n\\n\\n\\n","nuxtjs-light":"\\n\\n\\n\\n\\n","php-dark":"\\n\\n\\n\\n\\n\\n","php-light":"\\n\\n\\n\\n\\n\\n","postgresql-dark":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","postgresql-light":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","prisma":"\\n\\n\\n\\n","python-dark":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","python-light":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","react-dark":"\\n\\n\\n\\n\\n\\n\\n","react-light":"\\n\\n\\n\\n\\n\\n\\n","redis-dark":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","redis-light":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","ruby":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","rust":"\\n\\n\\n\\n","svelte":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","swift":"\\n\\n\\n\\n","tailwindcss-dark":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","tailwindcss-light":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n","typescript":"\\n\\n\\n\\n\\n","vim-dark":"\\n\\n\\n\\n\\n","vim-light":"\\n\\n\\n\\n\\n","vuejs-dark":"\\n\\n\\n\\n\\n\\n","vuejs-light":"\\n\\n\\n\\n\\n\\n","webassembly":"\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n"}')}]); \ No newline at end of file