From 386cf83fa693e9e71c40bc4e9d5c02a6e5048d53 Mon Sep 17 00:00:00 2001 From: Rodrigo Pombo Date: Tue, 25 Feb 2025 18:47:47 +0100 Subject: [PATCH] Guess codeblock icon from lang (#257) --- package.json | 1 - src/app/components/code/code-icon.tsx | 8 +++----- src/app/components/code/code.tsx | 5 +++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 9293718c..cfa4e088 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "@typeform/embed": "^5.1.0", "bootstrap": "^5.3.3", "cheerio": "^1.0.0", - "class-variance-authority": "^0.7.1", "classnames": "^2.5.1", "codehike": "^1.0.4", "date-fns": "^4.1.0", diff --git a/src/app/components/code/code-icon.tsx b/src/app/components/code/code-icon.tsx index 8b9f62cd..0853737a 100644 --- a/src/app/components/code/code-icon.tsx +++ b/src/app/components/code/code-icon.tsx @@ -26,11 +26,9 @@ export function CodeIcon({ ); } - let filename = title || "x"; - if (!filename.includes(".")) { - const ext = lang === "rust" ? "rs" : lang === "typescript" ? "ts" : lang; - filename += "." + ext; - } + const ext = lang === "rust" ? "rs" : lang === "typescript" ? "ts" : lang; + const filename = "x." + ext; + const { svg, color } = getIcon(filename); const __html = svg.replace( /svg/, diff --git a/src/app/components/code/code.tsx b/src/app/components/code/code.tsx index 9ae5f531..444d58da 100644 --- a/src/app/components/code/code.tsx +++ b/src/app/components/code/code.tsx @@ -138,8 +138,9 @@ function getHandlers(options: CodeGroup["options"]) { function extractFlags(codeblock: RawCode) { const flags = codeblock.meta.split(" ").filter((flag) => flag.startsWith("-"))[0] ?? ""; - const metaWithoutFlags = - codeblock.meta === flags + const metaWithoutFlags = !flags + ? codeblock.meta + : codeblock.meta === flags ? "" : codeblock.meta.replace(" " + flags, "").trim(); const title = getTitle(metaWithoutFlags);