internal/httpd/langs.go
42 lines · 1688 bytes
1package httpd
2
3import (
4 "path"
5 "strings"
6)
7
8// langByExt names the languages worth reporting on a repository home. It is
9// deliberately short: the point is "what is this written in", not a
10// linguist-grade census, and an unlisted extension simply does not count.
11var langByExt = map[string]string{
12 ".go": "Go", ".rs": "Rust", ".c": "C", ".h": "C", ".cc": "C++",
13 ".cpp": "C++", ".hpp": "C++", ".cs": "C#", ".java": "Java",
14 ".kt": "Kotlin", ".swift": "Swift", ".m": "Objective-C",
15 ".py": "Python", ".rb": "Ruby", ".pl": "Perl", ".php": "PHP",
16 ".js": "JavaScript", ".mjs": "JavaScript", ".jsx": "JavaScript",
17 ".ts": "TypeScript", ".tsx": "TypeScript",
18 ".sh": "Shell", ".bash": "Shell", ".zsh": "Shell", ".fish": "Shell",
19 ".lua": "Lua", ".el": "Emacs Lisp", ".lisp": "Common Lisp",
20 ".clj": "Clojure", ".ex": "Elixir", ".exs": "Elixir", ".erl": "Erlang",
21 ".hs": "Haskell", ".ml": "OCaml", ".scala": "Scala", ".dart": "Dart",
22 ".zig": "Zig", ".nim": "Nim", ".jl": "Julia", ".r": "R",
23 ".sql": "SQL", ".html": "HTML", ".css": "CSS", ".scss": "SCSS",
24 ".vim": "Vim script", ".tf": "HCL", ".nix": "Nix",
25 ".org": "Org", ".md": "Markdown", ".tex": "TeX",
26}
27
28// langOf maps a path to a language name, or "" when it is not code we
29// count. Vendored and generated trees are excluded: they describe someone
30// else's work, and including them makes the bar meaningless.
31func langOf(p string) string {
32 for _, seg := range strings.Split(p, "/") {
33 switch seg {
34 case "vendor", "node_modules", "third_party", "testdata", "dist":
35 return ""
36 }
37 }
38 if strings.HasSuffix(p, ".min.js") || strings.HasSuffix(p, ".min.css") {
39 return ""
40 }
41 return langByExt[strings.ToLower(path.Ext(p))]
42}