| 51 | } |
| 52 | |
| 53 | export function detectLanguage(filePath: string): string { |
| 54 | const filename = filePath.split("/").pop()?.toLowerCase() ?? ""; |
| 55 | if (filename === "dockerfile") return "dockerfile"; |
| 56 | if (filename === "makefile" || filename === "gnumakefile") return "makefile"; |
| 57 | |
| 58 | const ext = filename.split(".").pop() ?? ""; |
| 59 | const map: Record<string, string> = { |
| 60 | ts: "typescript", tsx: "tsx", js: "javascript", jsx: "jsx", |
| 61 | mjs: "javascript", cjs: "javascript", |
| 62 | py: "python", rs: "rust", go: "go", |
| 63 | css: "css", scss: "scss", less: "less", |
| 64 | html: "html", htm: "html", |
| 65 | json: "json", jsonc: "json", |
| 66 | md: "markdown", mdx: "markdown", |
| 67 | sh: "bash", bash: "bash", zsh: "bash", |
| 68 | yml: "yaml", yaml: "yaml", |
| 69 | toml: "toml", sql: "sql", |
| 70 | graphql: "graphql", gql: "graphql", |
| 71 | rb: "ruby", java: "java", |
| 72 | c: "c", cpp: "cpp", cc: "cpp", cxx: "cpp", |
| 73 | h: "c", hpp: "cpp", |
| 74 | cs: "csharp", php: "php", |
| 75 | swift: "swift", kt: "kotlin", |
| 76 | r: "r", scala: "scala", |
| 77 | ex: "elixir", exs: "elixir", |
| 78 | vue: "vue", svelte: "svelte", |
| 79 | xml: "xml", |
| 80 | }; |
| 81 | return map[ext] ?? "text"; |
| 82 | } |
| 83 | |
| 84 | function getFilename(filePath: string): string { |
| 85 | return filePath.split("/").pop() ?? filePath; |