about summary refs log tree commit diff stats
path: root/res/mime.types
Commit message (Expand)AuthorAgeFilesLines
* res/mime.types: add gmi extensionbptato2024-02-141-0/+1
* Add default md2html converterbptato2024-01-301-0/+1
* Add mailcap, mime.types & misc refactoringsbptato2023-08-131-0/+10
'n40' href='#n40'>40 41 42 43 44 45 46 47 48 49 50 51
import algorithm
import tables

const DefaultGuess = [
  ("html", "text/html"),
  ("htm", "text/html"),
  ("xhtml", "application/xhtml+xml"),
  ("xhtm", "application/xhtml+xml"),
  ("xht", "application/xhtml+xml"),
  ("txt", "text/plain"),
  ("css", "text/css"),
  ("", "text/plain")
].toTable()

proc guessContentType*(path: string, def = DefaultGuess[""]): string =
  var i = path.len - 1
  var n = 0
  while i > 0:
    if path[i] == '/':
      return def
    if path[i] == '.':
      n = i
      break
    dec i
  if n > 0:
    let ext = path.substr(n + 1)
    if ext in DefaultGuess:
      return DefaultGuess[ext]
  return def

const JavaScriptTypes = [
  "application/ecmascript",
  "application/javascript",
  "application/x-ecmascript",
  "application/x-javascript",
  "text/ecmascript",
  "text/javascript",
  "text/javascript1.0",
  "text/javascript1.1",
  "text/javascript1.2",
  "text/javascript1.3",
  "text/javascript1.4",
  "text/javascript1.5",
  "text/jscript",
  "text/livescript",
  "text/x-ecmascript",
  "text/x-javascript"
]

proc isJavaScriptType*(s: string): bool =
  return binarySearch(JavaScriptTypes, s) != -1