Skip to content

Commit

Permalink
Guess codeblock icon from lang (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber authored Feb 25, 2025
1 parent ffe4e61 commit 386cf83
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions src/app/components/code/code-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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/,
Expand Down
5 changes: 3 additions & 2 deletions src/app/components/code/code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 386cf83

Please sign in to comment.