Skip to content

Commit be1edc3

Browse files
fix(site): fix language detection for Dockerfile (#12188)
1 parent 41647ca commit be1edc3

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

site/src/modules/templates/TemplateFiles/TemplateFiles.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@ import { TemplateFileTree } from "./TemplateFileTree";
99
import { Link } from "react-router-dom";
1010
import EditOutlined from "@mui/icons-material/EditOutlined";
1111

12-
const languageByExtension: Record<string, string> = {
13-
tf: "hcl",
14-
hcl: "hcl",
15-
md: "markdown",
16-
mkd: "markdown",
17-
Dockerfile: "dockerfile",
18-
sh: "shell",
19-
tpl: "tpl",
20-
protobuf: "protobuf",
21-
nix: "dockerfile",
22-
};
2312
interface TemplateFilesProps {
2413
currentFiles: TemplateVersionFiles;
2514
/**
@@ -135,9 +124,7 @@ export const TemplateFiles: FC<TemplateFilesProps> = ({
135124
</div>
136125
</header>
137126
<SyntaxHighlighter
138-
language={
139-
languageByExtension[filename.split(".").pop() ?? ""]
140-
}
127+
language={getLanguage(filename)}
141128
value={info.value}
142129
compareWith={info.previousValue}
143130
editorProps={{
@@ -159,6 +146,27 @@ export const TemplateFiles: FC<TemplateFilesProps> = ({
159146
);
160147
};
161148

149+
const languageByExtension: Record<string, string> = {
150+
tf: "hcl",
151+
hcl: "hcl",
152+
md: "markdown",
153+
mkd: "markdown",
154+
sh: "shell",
155+
tpl: "tpl",
156+
protobuf: "protobuf",
157+
nix: "dockerfile",
158+
json: "json",
159+
};
160+
161+
const getLanguage = (filename: string) => {
162+
// Dockerfile can be like images/Dockerfile or Dockerfile.java
163+
if (filename.includes("Dockerfile")) {
164+
return "dockerfile";
165+
}
166+
const extension = filename.split(".").pop();
167+
return languageByExtension[extension ?? ""];
168+
};
169+
162170
const numberOfLines = (content: string) => {
163171
return content.split("\n").length;
164172
};

0 commit comments

Comments
 (0)