From 25e12e9c038c5e499feb909fbbfbb5005e4eeb00 Mon Sep 17 00:00:00 2001 From: David Paz Date: Mon, 10 Jul 2017 12:59:39 +0200 Subject: [PATCH] Returns text/plain when mime it's undefined --- data/mime.go | 461 +++++++++++++++++++++++++++++++++++++++++++++++++++ utils.go | 8 +- 2 files changed, 467 insertions(+), 2 deletions(-) create mode 100644 data/mime.go diff --git a/data/mime.go b/data/mime.go new file mode 100644 index 0000000..7a105bc --- /dev/null +++ b/data/mime.go @@ -0,0 +1,461 @@ +package data + +// CODE GENERATED AUTOMATICALLY WITH gopkg.in/src-d/enry.v1/internal/code-generator +// THIS FILE SHOULD NOT BE EDITED BY HAND +// Extracted from github/linguist commit: d5c8db3fb91963c4b2762ca2ea2ff7cfac109f68 + +var LanguagesMime = map[string]string{ + "1C Enterprise": "", + "ABAP": "", + "ABNF": "", + "AGS Script": "text/x-c++src", + "AMPL": "", + "ANTLR": "", + "API Blueprint": "", + "APL": "text/apl", + "ASN.1": "text/x-ttcn-asn", + "ASP": "application/x-aspx", + "ATS": "", + "ActionScript": "", + "Ada": "", + "Agda": "", + "Alloy": "", + "Alpine Abuild": "text/x-sh", + "Ant Build System": "application/xml", + "ApacheConf": "", + "Apex": "text/x-java", + "Apollo Guidance Computer": "", + "AppleScript": "", + "Arc": "", + "Arduino": "text/x-c++src", + "AsciiDoc": "", + "AspectJ": "", + "Assembly": "", + "Augeas": "", + "AutoHotkey": "", + "AutoIt": "", + "Awk": "", + "Batchfile": "", + "Befunge": "", + "Bison": "", + "BitBake": "", + "Blade": "", + "BlitzBasic": "", + "BlitzMax": "", + "Bluespec": "", + "Boo": "", + "Brainfuck": "text/x-brainfuck", + "Brightscript": "", + "Bro": "", + "C": "text/x-csrc", + "C#": "text/x-csharp", + "C++": "text/x-c++src", + "C-ObjDump": "", + "C2hs Haskell": "text/x-haskell", + "CLIPS": "", + "CMake": "text/x-cmake", + "COBOL": "text/x-cobol", + "COLLADA": "text/xml", + "CSON": "text/x-coffeescript", + "CSS": "text/css", + "CSV": "", + "CWeb": "", + "Cap'n Proto": "", + "CartoCSS": "", + "Ceylon": "", + "Chapel": "", + "Charity": "", + "ChucK": "text/x-java", + "Cirru": "", + "Clarion": "", + "Clean": "", + "Click": "", + "Clojure": "text/x-clojure", + "Closure Templates": "text/x-soy", + "CoffeeScript": "text/x-coffeescript", + "ColdFusion": "", + "ColdFusion CFC": "", + "Common Lisp": "text/x-common-lisp", + "Component Pascal": "text/x-pascal", + "Cool": "", + "Coq": "", + "Cpp-ObjDump": "", + "Creole": "", + "Crystal": "text/x-crystal", + "Csound": "", + "Csound Document": "", + "Csound Score": "", + "Cuda": "text/x-c++src", + "Cycript": "text/javascript", + "Cython": "text/x-cython", + "D": "text/x-d", + "D-ObjDump": "", + "DIGITAL Command Language": "", + "DM": "", + "DNS Zone": "", + "DTrace": "text/x-csrc", + "Darcs Patch": "", + "Dart": "application/dart", + "Diff": "text/x-diff", + "Dockerfile": "text/x-dockerfile", + "Dogescript": "", + "Dylan": "text/x-dylan", + "E": "", + "EBNF": "text/x-ebnf", + "ECL": "text/x-ecl", + "ECLiPSe": "", + "EJS": "", + "EQ": "text/x-csharp", + "Eagle": "text/xml", + "Easybuild": "text/x-python", + "Ecere Projects": "application/json", + "Eiffel": "text/x-eiffel", + "Elixir": "", + "Elm": "text/x-elm", + "Emacs Lisp": "text/x-common-lisp", + "EmberScript": "text/x-coffeescript", + "Erlang": "text/x-erlang", + "F#": "text/x-fsharp", + "FLUX": "", + "Factor": "text/x-factor", + "Fancy": "", + "Fantom": "", + "Filebench WML": "", + "Filterscript": "", + "Formatted": "", + "Forth": "text/x-forth", + "Fortran": "text/x-fortran", + "FreeMarker": "", + "Frege": "", + "G-code": "", + "GAMS": "", + "GAP": "", + "GCC Machine Description": "text/x-common-lisp", + "GDB": "", + "GDScript": "", + "GLSL": "", + "GN": "text/x-python", + "Game Maker Language": "text/x-c++src", + "Genie": "", + "Genshi": "text/xml", + "Gentoo Ebuild": "text/x-sh", + "Gentoo Eclass": "text/x-sh", + "Gettext Catalog": "", + "Gherkin": "", + "Glyph": "text/x-tcl", + "Gnuplot": "", + "Go": "text/x-go", + "Golo": "", + "Gosu": "", + "Grace": "", + "Gradle": "", + "Grammatical Framework": "text/x-haskell", + "Graph Modeling Language": "", + "GraphQL": "", + "Graphviz (DOT)": "", + "Groovy": "text/x-groovy", + "Groovy Server Pages": "application/x-jsp", + "HCL": "text/x-ruby", + "HLSL": "", + "HTML": "text/html", + "HTML+Django": "text/x-django", + "HTML+ECR": "text/html", + "HTML+EEX": "text/html", + "HTML+ERB": "application/x-erb", + "HTML+PHP": "application/x-httpd-php", + "HTTP": "message/http", + "Hack": "application/x-httpd-php", + "Haml": "text/x-haml", + "Handlebars": "", + "Harbour": "", + "Haskell": "text/x-haskell", + "Haxe": "text/x-haxe", + "Hy": "", + "HyPhy": "", + "IDL": "text/x-idl", + "IGOR Pro": "", + "INI": "text/x-properties", + "IRC log": "text/mirc", + "Idris": "", + "Inform 7": "", + "Inno Setup": "", + "Io": "", + "Ioke": "", + "Isabelle": "", + "Isabelle ROOT": "", + "J": "", + "JFlex": "", + "JSON": "application/json", + "JSON5": "application/json", + "JSONLD": "", + "JSONiq": "application/json", + "JSX": "text/jsx", + "Jasmin": "", + "Java": "text/x-java", + "Java Server Pages": "application/x-jsp", + "JavaScript": "text/javascript", + "Jison": "", + "Jison Lex": "", + "Jolie": "", + "Julia": "text/x-julia", + "Jupyter Notebook": "application/json", + "KRL": "", + "KiCad": "", + "Kit": "text/html", + "Kotlin": "text/x-kotlin", + "LFE": "text/x-common-lisp", + "LLVM": "", + "LOLCODE": "", + "LSL": "", + "LabVIEW": "text/xml", + "Lasso": "", + "Latte": "text/x-smarty", + "Lean": "", + "Less": "text/css", + "Lex": "", + "LilyPond": "", + "Limbo": "", + "Linker Script": "", + "Linux Kernel Module": "", + "Liquid": "", + "Literate Agda": "", + "Literate CoffeeScript": "", + "Literate Haskell": "text/x-literate-haskell", + "LiveScript": "text/x-livescript", + "Logos": "", + "Logtalk": "", + "LookML": "text/x-yaml", + "LoomScript": "", + "Lua": "text/x-lua", + "M": "text/x-mumps", + "M4": "", + "M4Sugar": "", + "MAXScript": "", + "MQL4": "", + "MQL5": "", + "MTML": "text/html", + "MUF": "text/x-forth", + "Makefile": "text/x-cmake", + "Mako": "", + "Markdown": "text/x-gfm", + "Marko": "text/html", + "Mask": "", + "Mathematica": "text/x-mathematica", + "Matlab": "text/x-octave", + "Maven POM": "text/xml", + "Max": "application/json", + "MediaWiki": "", + "Mercury": "", + "Meson": "", + "Metal": "text/x-c++src", + "MiniD": "", + "Mirah": "text/x-ruby", + "Modelica": "text/x-modelica", + "Modula-2": "", + "Module Management System": "", + "Monkey": "", + "Moocode": "", + "MoonScript": "", + "Myghty": "", + "NCL": "", + "NL": "", + "NSIS": "text/x-nsis", + "Nemerle": "", + "NetLinx": "", + "NetLinx+ERB": "", + "NetLogo": "text/x-common-lisp", + "NewLisp": "text/x-common-lisp", + "Nginx": "text/x-nginx-conf", + "Nim": "", + "Ninja": "", + "Nit": "", + "Nix": "", + "Nu": "text/x-scheme", + "NumPy": "text/x-python", + "OCaml": "text/x-ocaml", + "ObjDump": "", + "Objective-C": "text/x-objectivec", + "Objective-C++": "text/x-objectivec", + "Objective-J": "", + "Omgrofl": "", + "Opa": "", + "Opal": "", + "OpenCL": "text/x-csrc", + "OpenEdge ABL": "", + "OpenRC runscript": "text/x-sh", + "OpenSCAD": "", + "OpenType Feature File": "", + "Org": "", + "Ox": "", + "Oxygene": "", + "Oz": "text/x-oz", + "P4": "", + "PAWN": "", + "PHP": "application/x-httpd-php", + "PLSQL": "text/x-plsql", + "PLpgSQL": "text/x-sql", + "POV-Ray SDL": "", + "Pan": "", + "Papyrus": "", + "Parrot": "", + "Parrot Assembly": "", + "Parrot Internal Representation": "", + "Pascal": "text/x-pascal", + "Pep8": "", + "Perl": "text/x-perl", + "Perl 6": "text/x-perl", + "Pic": "text/troff", + "Pickle": "", + "PicoLisp": "", + "PigLatin": "", + "Pike": "", + "Pod": "text/x-perl", + "PogoScript": "", + "Pony": "", + "PostScript": "", + "PowerBuilder": "", + "PowerShell": "application/x-powershell", + "Processing": "", + "Prolog": "", + "Propeller Spin": "", + "Protocol Buffer": "text/x-protobuf", + "Public Key": "application/pgp", + "Pug": "text/x-pug", + "Puppet": "text/x-puppet", + "Pure Data": "", + "PureBasic": "", + "PureScript": "text/x-haskell", + "Python": "text/x-python", + "Python console": "", + "Python traceback": "", + "QML": "", + "QMake": "", + "R": "text/x-rsrc", + "RAML": "text/x-yaml", + "RDoc": "", + "REALbasic": "", + "REXX": "", + "RHTML": "application/x-erb", + "RMarkdown": "text/x-gfm", + "RPM Spec": "text/x-rpm-spec", + "RUNOFF": "", + "Racket": "", + "Ragel": "", + "Rascal": "", + "Raw token data": "", + "Reason": "text/x-rustsrc", + "Rebol": "", + "Red": "", + "Redcode": "", + "Regular Expression": "", + "Ren'Py": "", + "RenderScript": "", + "Ring": "", + "RobotFramework": "", + "Roff": "text/troff", + "Rouge": "text/x-clojure", + "Ruby": "text/x-ruby", + "Rust": "text/x-rustsrc", + "SAS": "text/x-sas", + "SCSS": "text/x-scss", + "SMT": "", + "SPARQL": "application/sparql-query", + "SQF": "", + "SQL": "text/x-sql", + "SQLPL": "text/x-sql", + "SRecode Template": "text/x-common-lisp", + "STON": "", + "SVG": "text/xml", + "Sage": "text/x-python", + "SaltStack": "text/x-yaml", + "Sass": "text/x-sass", + "Scala": "text/x-scala", + "Scaml": "", + "Scheme": "text/x-scheme", + "Scilab": "", + "Self": "", + "ShaderLab": "", + "Shell": "text/x-sh", + "ShellSession": "text/x-sh", + "Shen": "", + "Slash": "", + "Slim": "text/x-slim", + "Smali": "", + "Smalltalk": "text/x-stsrc", + "Smarty": "text/x-smarty", + "SourcePawn": "", + "Spline Font Database": "", + "Squirrel": "text/x-c++src", + "Stan": "", + "Standard ML": "text/x-ocaml", + "Stata": "", + "Stylus": "", + "SubRip Text": "", + "Sublime Text Config": "text/javascript", + "SuperCollider": "", + "Swift": "text/x-swift", + "SystemVerilog": "text/x-systemverilog", + "TI Program": "", + "TLA": "", + "TOML": "text/x-toml", + "TXL": "", + "Tcl": "text/x-tcl", + "Tcsh": "text/x-sh", + "TeX": "text/x-stex", + "Tea": "", + "Terra": "text/x-lua", + "Text": "", + "Textile": "text/x-textile", + "Thrift": "", + "Turing": "", + "Turtle": "text/turtle", + "Twig": "text/x-twig", + "Type Language": "", + "TypeScript": "application/typescript", + "Unified Parallel C": "text/x-csrc", + "Unity3D Asset": "text/x-yaml", + "Unix Assembly": "", + "Uno": "text/x-csharp", + "UnrealScript": "text/x-java", + "UrWeb": "", + "VCL": "", + "VHDL": "text/x-vhdl", + "Vala": "", + "Verilog": "text/x-verilog", + "Vim script": "", + "Visual Basic": "text/x-vb", + "Volt": "text/x-d", + "Vue": "", + "Wavefront Material": "", + "Wavefront Object": "", + "Web Ontology Language": "", + "WebAssembly": "text/x-common-lisp", + "WebIDL": "text/x-webidl", + "World of Warcraft Addon Data": "", + "X10": "", + "XC": "text/x-csrc", + "XCompose": "", + "XML": "text/xml", + "XPages": "text/xml", + "XProc": "text/xml", + "XQuery": "application/xquery", + "XS": "text/x-csrc", + "XSLT": "text/xml", + "Xojo": "", + "Xtend": "", + "YAML": "text/x-yaml", + "YANG": "", + "Yacc": "", + "Zephir": "", + "Zimpl": "", + "desktop": "", + "eC": "", + "edn": "text/x-clojure", + "fish": "", + "mupad": "", + "nesC": "", + "ooc": "", + "reStructuredText": "text/x-rst", + "wisp": "text/x-clojure", + "xBase": "", +} diff --git a/utils.go b/utils.go index 9aaa4c8..2df533c 100644 --- a/utils.go +++ b/utils.go @@ -53,8 +53,12 @@ func IsDocumentation(path string) bool { return data.DocumentationMatchers.Match(path) } -func GetMimeType(file string) string { - return data.LanguagesMime[file] +func GetMimeType(language string) string { + if mime, ok := data.LanguagesMime[language]; ok { + return mime + } + + return "text/plain" } const sniffLen = 8000