1 ;;; Haunt --- Static site generator for GNU Guile
2 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
4 ;;; This file is part of Haunt.
6 ;;; Haunt is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or
9 ;;; (at your option) any later version.
11 ;;; Haunt is distributed in the hope that it will be useful, but
12 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ;;; General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with Haunt. If not, see <http://www.gnu.org/licenses/>.
21 ;; Simple MIME type guesser.
25 (define-module (mudsync contrib mime-types)
26 #:use-module (ice-9 hash-table)
27 #:use-module (ice-9 regex)
32 '(("ez" . application/andrew-inset)
33 ("anx" . application/annodex)
34 ("atom" . application/atom+xml)
35 ("atomcat" . application/atomcat+xml)
36 ("atomsrv" . application/atomserv+xml)
37 ("lin" . application/bbolin)
38 ("cap" . application/cap)
39 ("pcap" . application/cap)
40 ("cu" . application/cu-seeme)
41 ("davmount" . application/davmount+xml)
42 ("tsp" . application/dsptype)
43 ("es" . application/ecmascript)
44 ("spl" . application/futuresplash)
45 ("hta" . application/hta)
46 ("jar" . application/java-archive)
47 ("ser" . application/java-serialized-object)
48 ("class" . application/java-vm)
49 ("js" . application/javascript)
50 ("m3g" . application/m3g)
51 ("hqx" . application/mac-binhex40)
52 ("cpt" . application/mac-compactpro)
53 ("nb" . application/mathematica)
54 ("nbp" . application/mathematica)
55 ("mdb" . application/msaccess)
56 ("doc" . application/msword)
57 ("dot" . application/msword)
58 ("mxf" . application/mxf)
59 ("bin" . application/octet-stream)
60 ("oda" . application/oda)
61 ("ogx" . application/ogg)
62 ("pdf" . application/pdf)
63 ("key" . application/pgp-keys)
64 ("pgp" . application/pgp-signature)
65 ("prf" . application/pics-rules)
66 ("ps" . application/postscript)
67 ("ai" . application/postscript)
68 ("eps" . application/postscript)
69 ("epsi" . application/postscript)
70 ("epsf" . application/postscript)
71 ("eps2" . application/postscript)
72 ("eps3" . application/postscript)
73 ("rar" . application/rar)
74 ("rdf" . application/rdf+xml)
75 ("rss" . application/rss+xml)
76 ("rtf" . application/rtf)
77 ("smi" . application/smil)
78 ("smil" . application/smil)
79 ("xhtml" . application/xhtml+xml)
80 ("xht" . application/xhtml+xml)
81 ("xml" . application/xml)
82 ("xsl" . application/xml)
83 ("xsd" . application/xml)
84 ("xspf" . application/xspf+xml)
85 ("zip" . application/zip)
86 ("apk" . application/vnd.android.package-archive)
87 ("cdy" . application/vnd.cinderella)
88 ("kml" . application/vnd.google-earth.kml+xml)
89 ("kmz" . application/vnd.google-earth.kmz)
90 ("xul" . application/vnd.mozilla.xul+xml)
91 ("xls" . application/vnd.ms-excel)
92 ("xlb" . application/vnd.ms-excel)
93 ("xlt" . application/vnd.ms-excel)
94 ("cat" . application/vnd.ms-pki.seccat)
95 ("stl" . application/vnd.ms-pki.stl)
96 ("ppt" . application/vnd.ms-powerpoint)
97 ("pps" . application/vnd.ms-powerpoint)
98 ("odc" . application/vnd.oasis.opendocument.chart)
99 ("odb" . application/vnd.oasis.opendocument.database)
100 ("odf" . application/vnd.oasis.opendocument.formula)
101 ("odg" . application/vnd.oasis.opendocument.graphics)
102 ("otg" . application/vnd.oasis.opendocument.graphics-template)
103 ("odi" . application/vnd.oasis.opendocument.image)
104 ("odp" . application/vnd.oasis.opendocument.presentation)
105 ("otp" . application/vnd.oasis.opendocument.presentation-template)
106 ("ods" . application/vnd.oasis.opendocument.spreadsheet)
107 ("ots" . application/vnd.oasis.opendocument.spreadsheet-template)
108 ("odt" . application/vnd.oasis.opendocument.text)
109 ("odm" . application/vnd.oasis.opendocument.text-master)
110 ("ott" . application/vnd.oasis.opendocument.text-template)
111 ("oth" . application/vnd.oasis.opendocument.text-web)
112 ("xlsx" . application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
113 ("xltx" . application/vnd.openxmlformats-officedocument.spreadsheetml.template)
114 ("pptx" . application/vnd.openxmlformats-officedocument.presentationml.presentation)
115 ("ppsx" . application/vnd.openxmlformats-officedocument.presentationml.slideshow)
116 ("potx" . application/vnd.openxmlformats-officedocument.presentationml.template)
117 ("docx" . application/vnd.openxmlformats-officedocument.wordprocessingml.document)
118 ("dotx" . application/vnd.openxmlformats-officedocument.wordprocessingml.template)
119 ("cod" . application/vnd.rim.cod)
120 ("mmf" . application/vnd.smaf)
121 ("sdc" . application/vnd.stardivision.calc)
122 ("sds" . application/vnd.stardivision.chart)
123 ("sda" . application/vnd.stardivision.draw)
124 ("sdd" . application/vnd.stardivision.impress)
125 ("sdf" . application/vnd.stardivision.math)
126 ("sdw" . application/vnd.stardivision.writer)
127 ("sgl" . application/vnd.stardivision.writer-global)
128 ("sxc" . application/vnd.sun.xml.calc)
129 ("stc" . application/vnd.sun.xml.calc.template)
130 ("sxd" . application/vnd.sun.xml.draw)
131 ("std" . application/vnd.sun.xml.draw.template)
132 ("sxi" . application/vnd.sun.xml.impress)
133 ("sti" . application/vnd.sun.xml.impress.template)
134 ("sxm" . application/vnd.sun.xml.math)
135 ("sxw" . application/vnd.sun.xml.writer)
136 ("sxg" . application/vnd.sun.xml.writer.global)
137 ("stw" . application/vnd.sun.xml.writer.template)
138 ("sis" . application/vnd.symbian.install)
139 ("vsd" . application/vnd.visio)
140 ("wbxml" . application/vnd.wap.wbxml)
141 ("wmlc" . application/vnd.wap.wmlc)
142 ("wmlsc" . application/vnd.wap.wmlscriptc)
143 ("wpd" . application/vnd.wordperfect)
144 ("wp5" . application/vnd.wordperfect5.1)
145 ("wk" . application/x-123)
146 ("7z" . application/x-7z-compressed)
147 ("bz2" . application/x-bzip2)
148 ("gz" . application/x-gzip)
149 ("abw" . application/x-abiword)
150 ("dmg" . application/x-apple-diskimage)
151 ("bcpio" . application/x-bcpio)
152 ("torrent" . application/x-bittorrent)
153 ("cab" . application/x-cab)
154 ("cbr" . application/x-cbr)
155 ("cbz" . application/x-cbz)
156 ("cdf" . application/x-cdf)
157 ("cda" . application/x-cdf)
158 ("vcd" . application/x-cdlink)
159 ("pgn" . application/x-chess-pgn)
160 ("cpio" . application/x-cpio)
161 ("csh" . application/x-csh)
162 ("deb" . application/x-debian-package)
163 ("udeb" . application/x-debian-package)
164 ("dcr" . application/x-director)
165 ("dir" . application/x-director)
166 ("dxr" . application/x-director)
167 ("dms" . application/x-dms)
168 ("wad" . application/x-doom)
169 ("dvi" . application/x-dvi)
170 ("rhtml" . application/x-httpd-eruby)
171 ("pfa" . application/x-font)
172 ("pfb" . application/x-font)
173 ("gsf" . application/x-font)
174 ("pcf" . application/x-font)
175 ("pcf.Z" . application/x-font)
176 ("mm" . application/x-freemind)
177 ("spl" . application/x-futuresplash)
178 ("gnumeric" . application/x-gnumeric)
179 ("sgf" . application/x-go-sgf)
180 ("gcf" . application/x-graphing-calculator)
181 ("gtar" . application/x-gtar)
182 ("tgz" . application/x-gtar)
183 ("taz" . application/x-gtar)
184 ("tar.gz" . application/x-gtar)
185 ("tar.bz2" . application/x-gtar)
186 ("tbz2" . application/x-gtar)
187 ("hdf" . application/x-hdf)
188 ("phtml" . application/x-httpd-php)
189 ("pht" . application/x-httpd-php)
190 ("php" . application/x-httpd-php)
191 ("phps" . application/x-httpd-php-source)
192 ("php3" . application/x-httpd-php3)
193 ("php3p" . application/x-httpd-php3-preprocessed)
194 ("php4" . application/x-httpd-php4)
195 ("php5" . application/x-httpd-php5)
196 ("ica" . application/x-ica)
197 ("info" . application/x-info)
198 ("ins" . application/x-internet-signup)
199 ("isp" . application/x-internet-signup)
200 ("iii" . application/x-iphone)
201 ("iso" . application/x-iso9660-image)
202 ("jam" . application/x-jam)
203 ("jnlp" . application/x-java-jnlp-file)
204 ("jmz" . application/x-jmol)
205 ("chrt" . application/x-kchart)
206 ("kil" . application/x-killustrator)
207 ("skp" . application/x-koan)
208 ("skd" . application/x-koan)
209 ("skt" . application/x-koan)
210 ("skm" . application/x-koan)
211 ("kpr" . application/x-kpresenter)
212 ("kpt" . application/x-kpresenter)
213 ("ksp" . application/x-kspread)
214 ("kwd" . application/x-kword)
215 ("kwt" . application/x-kword)
216 ("latex" . application/x-latex)
217 ("lha" . application/x-lha)
218 ("lyx" . application/x-lyx)
219 ("lzh" . application/x-lzh)
220 ("lzx" . application/x-lzx)
221 ("frm" . application/x-maker)
222 ("maker" . application/x-maker)
223 ("frame" . application/x-maker)
224 ("fm" . application/x-maker)
225 ("fb" . application/x-maker)
226 ("book" . application/x-maker)
227 ("fbdoc" . application/x-maker)
228 ("mif" . application/x-mif)
229 ("wmd" . application/x-ms-wmd)
230 ("wmz" . application/x-ms-wmz)
231 ("com" . application/x-msdos-program)
232 ("exe" . application/x-msdos-program)
233 ("bat" . application/x-msdos-program)
234 ("dll" . application/x-msdos-program)
235 ("msi" . application/x-msi)
236 ("nc" . application/x-netcdf)
237 ("pac" . application/x-ns-proxy-autoconfig)
238 ("dat" . application/x-ns-proxy-autoconfig)
239 ("nwc" . application/x-nwc)
240 ("o" . application/x-object)
241 ("oza" . application/x-oz-application)
242 ("p7r" . application/x-pkcs7-certreqresp)
243 ("crl" . application/x-pkcs7-crl)
244 ("pyc" . application/x-python-code)
245 ("pyo" . application/x-python-code)
246 ("qgs" . application/x-qgis)
247 ("shp" . application/x-qgis)
248 ("shx" . application/x-qgis)
249 ("qtl" . application/x-quicktimeplayer)
250 ("rpm" . application/x-redhat-package-manager)
251 ("rb" . application/x-ruby)
252 ("sh" . application/x-sh)
253 ("shar" . application/x-shar)
254 ("swf" . application/x-shockwave-flash)
255 ("swfl" . application/x-shockwave-flash)
256 ("scr" . application/x-silverlight)
257 ("sit" . application/x-stuffit)
258 ("sitx" . application/x-stuffit)
259 ("sv4cpio" . application/x-sv4cpio)
260 ("sv4crc" . application/x-sv4crc)
261 ("tar" . application/x-tar)
262 ("tcl" . application/x-tcl)
263 ("gf" . application/x-tex-gf)
264 ("pk" . application/x-tex-pk)
265 ("texinfo" . application/x-texinfo)
266 ("texi" . application/x-texinfo)
267 ("~" . application/x-trash)
268 ("%" . application/x-trash)
269 ("bak" . application/x-trash)
270 ("old" . application/x-trash)
271 ("sik" . application/x-trash)
272 ("t" . application/x-troff)
273 ("tr" . application/x-troff)
274 ("roff" . application/x-troff)
275 ("man" . application/x-troff-man)
276 ("me" . application/x-troff-me)
277 ("ms" . application/x-troff-ms)
278 ("ustar" . application/x-ustar)
279 ("src" . application/x-wais-source)
280 ("wz" . application/x-wingz)
281 ("crt" . application/x-x509-ca-cert)
282 ("xcf" . application/x-xcf)
283 ("fig" . application/x-xfig)
284 ("xpi" . application/x-xpinstall)
286 ("awb" . audio/amr-wb)
288 ("awb" . audio/amr-wb)
289 ("axa" . audio/annodex)
291 ("snd" . audio/basic)
292 ("flac" . audio/flac)
294 ("midi" . audio/midi)
296 ("mpga" . audio/mpeg)
297 ("mpega" . audio/mpeg)
301 ("m3u" . audio/mpegurl)
305 ("sid" . audio/prs.sid)
306 ("aif" . audio/x-aiff)
307 ("aiff" . audio/x-aiff)
308 ("aifc" . audio/x-aiff)
309 ("gsm" . audio/x-gsm)
310 ("m3u" . audio/x-mpegurl)
311 ("wma" . audio/x-ms-wma)
312 ("wax" . audio/x-ms-wax)
313 ("ra" . audio/x-pn-realaudio)
314 ("rm" . audio/x-pn-realaudio)
315 ("ram" . audio/x-pn-realaudio)
316 ("ra" . audio/x-realaudio)
317 ("pls" . audio/x-scpls)
318 ("sd2" . audio/x-sd2)
319 ("wav" . audio/x-wav)
320 ("alc" . chemical/x-alchemy)
321 ("cac" . chemical/x-cache)
322 ("cache" . chemical/x-cache)
323 ("csf" . chemical/x-cache-csf)
324 ("cbin" . chemical/x-cactvs-binary)
325 ("cascii" . chemical/x-cactvs-binary)
326 ("ctab" . chemical/x-cactvs-binary)
327 ("cdx" . chemical/x-cdx)
328 ("cer" . chemical/x-cerius)
329 ("c3d" . chemical/x-chem3d)
330 ("chm" . chemical/x-chemdraw)
331 ("cif" . chemical/x-cif)
332 ("cmdf" . chemical/x-cmdf)
333 ("cml" . chemical/x-cml)
334 ("cpa" . chemical/x-compass)
335 ("bsd" . chemical/x-crossfire)
336 ("csml" . chemical/x-csml)
337 ("csm" . chemical/x-csml)
338 ("ctx" . chemical/x-ctx)
339 ("cxf" . chemical/x-cxf)
340 ("cef" . chemical/x-cxf)
341 ("emb" . chemical/x-embl-dl-nucleotide)
342 ("embl" . chemical/x-embl-dl-nucleotide)
343 ("spc" . chemical/x-galactic-spc)
344 ("inp" . chemical/x-gamess-input)
345 ("gam" . chemical/x-gamess-input)
346 ("gamin" . chemical/x-gamess-input)
347 ("fch" . chemical/x-gaussian-checkpoint)
348 ("fchk" . chemical/x-gaussian-checkpoint)
349 ("cub" . chemical/x-gaussian-cube)
350 ("gau" . chemical/x-gaussian-input)
351 ("gjc" . chemical/x-gaussian-input)
352 ("gjf" . chemical/x-gaussian-input)
353 ("gal" . chemical/x-gaussian-log)
354 ("gcg" . chemical/x-gcg8-sequence)
355 ("gen" . chemical/x-genbank)
356 ("hin" . chemical/x-hin)
357 ("istr" . chemical/x-isostar)
358 ("ist" . chemical/x-isostar)
359 ("jdx" . chemical/x-jcamp-dx)
360 ("dx" . chemical/x-jcamp-dx)
361 ("kin" . chemical/x-kinemage)
362 ("mcm" . chemical/x-macmolecule)
363 ("mmd" . chemical/x-macromodel-input)
364 ("mmod" . chemical/x-macromodel-input)
365 ("mol" . chemical/x-mdl-molfile)
366 ("rd" . chemical/x-mdl-rdfile)
367 ("rxn" . chemical/x-mdl-rxnfile)
368 ("sd" . chemical/x-mdl-sdfile)
369 ("sdf" . chemical/x-mdl-sdfile)
370 ("tgf" . chemical/x-mdl-tgf)
371 ("mcif" . chemical/x-mmcif)
372 ("mol2" . chemical/x-mol2)
373 ("b" . chemical/x-molconn-Z)
374 ("gpt" . chemical/x-mopac-graph)
375 ("mop" . chemical/x-mopac-input)
376 ("mopcrt" . chemical/x-mopac-input)
377 ("mpc" . chemical/x-mopac-input)
378 ("zmt" . chemical/x-mopac-input)
379 ("moo" . chemical/x-mopac-out)
380 ("mvb" . chemical/x-mopac-vib)
381 ("asn" . chemical/x-ncbi-asn1)
382 ("prt" . chemical/x-ncbi-asn1-ascii)
383 ("ent" . chemical/x-ncbi-asn1-ascii)
384 ("val" . chemical/x-ncbi-asn1-binary)
385 ("aso" . chemical/x-ncbi-asn1-binary)
386 ("asn" . chemical/x-ncbi-asn1-spec)
387 ("pdb" . chemical/x-pdb)
388 ("ent" . chemical/x-pdb)
389 ("ros" . chemical/x-rosdal)
390 ("sw" . chemical/x-swissprot)
391 ("vms" . chemical/x-vamas-iso14976)
392 ("vmd" . chemical/x-vmd)
393 ("xtel" . chemical/x-xtel)
394 ("xyz" . chemical/x-xyz)
397 ("jpeg" . image/jpeg)
402 ("svg" . image/svg+xml)
403 ("svgz" . image/svg+xml)
404 ("tiff" . image/tiff)
406 ("djvu" . image/vnd.djvu)
407 ("djv" . image/vnd.djvu)
408 ("wbmp" . image/vnd.wap.wbmp)
409 ("cr2" . image/x-canon-cr2)
410 ("crw" . image/x-canon-crw)
411 ("ras" . image/x-cmu-raster)
412 ("cdr" . image/x-coreldraw)
413 ("pat" . image/x-coreldrawpattern)
414 ("cdt" . image/x-coreldrawtemplate)
415 ("cpt" . image/x-corelphotopaint)
416 ("erf" . image/x-epson-erf)
417 ("ico" . image/x-icon)
419 ("jng" . image/x-jng)
420 ("bmp" . image/x-ms-bmp)
421 ("nef" . image/x-nikon-nef)
422 ("orf" . image/x-olympus-orf)
423 ("psd" . image/x-photoshop)
424 ("pnm" . image/x-portable-anymap)
425 ("pbm" . image/x-portable-bitmap)
426 ("pgm" . image/x-portable-graymap)
427 ("ppm" . image/x-portable-pixmap)
428 ("rgb" . image/x-rgb)
429 ("xbm" . image/x-xbitmap)
430 ("xpm" . image/x-xpixmap)
431 ("xwd" . image/x-xwindowdump)
432 ("eml" . message/rfc822)
434 ("iges" . model/iges)
436 ("mesh" . model/mesh)
437 ("silo" . model/mesh)
439 ("vrml" . model/vrml)
440 ("x3dv" . model/x3d+vrml)
441 ("x3d" . model/x3d+xml)
442 ("x3db" . model/x3d+binary)
443 ("manifest" . text/cache-manifest)
444 ("ics" . text/calendar)
445 ("icz" . text/calendar)
451 ("shtml" . text/html)
453 ("mml" . text/mathml)
456 ("text" . text/plain)
459 ("rtx" . text/richtext)
460 ("sct" . text/scriptlet)
461 ("wsc" . text/scriptlet)
462 ("tm" . text/texmacs)
463 ("ts" . text/texmacs)
464 ("tsv" . text/tab-separated-values)
465 ("jad" . text/vnd.sun.j2me.app-descriptor)
466 ("wml" . text/vnd.wap.wml)
467 ("wmls" . text/vnd.wap.wmlscript)
468 ("bib" . text/x-bibtex)
470 ("h++" . text/x-c++hdr)
471 ("hpp" . text/x-c++hdr)
472 ("hxx" . text/x-c++hdr)
473 ("hh" . text/x-c++hdr)
474 ("c++" . text/x-c++src)
475 ("cpp" . text/x-c++src)
476 ("cxx" . text/x-c++src)
477 ("cc" . text/x-c++src)
479 ("htc" . text/x-component)
483 ("diff" . text/x-diff)
484 ("patch" . text/x-diff)
485 ("hs" . text/x-haskell)
486 ("java" . text/x-java)
487 ("lhs" . text/x-literate-haskell)
489 ("p" . text/x-pascal)
490 ("pas" . text/x-pascal)
491 ("gcd" . text/x-pcs-gcd)
494 ("py" . text/x-python)
495 ("scala" . text/x-scala)
496 ("etx" . text/x-setext)
504 ("vcs" . text/x-vcalendar)
505 ("vcf" . text/x-vcard)
506 ("json" . text/javascript)
508 ("axv" . video/annodex)
514 ("mpeg" . video/mpeg)
518 ("qt" . video/quicktime)
519 ("mov" . video/quicktime)
521 ("mxu" . video/vnd.mpegurl)
522 ("flv" . video/x-flv)
523 ("lsf" . video/x-la-asf)
524 ("lsx" . video/x-la-asf)
525 ("mng" . video/x-mng)
526 ("asf" . video/x-ms-asf)
527 ("asx" . video/x-ms-asf)
528 ("wm" . video/x-ms-wm)
529 ("wmv" . video/x-ms-wmv)
530 ("wmx" . video/x-ms-wmx)
531 ("wvx" . video/x-ms-wvx)
532 ("avi" . video/x-msvideo)
533 ("movie" . video/x-sgi-movie)
534 ("mpv" . video/x-matroska)
535 ("mkv" . video/x-matroska)
536 ("ice" . x-conference/x-cooltalk)
537 ("sisx" . x-epoc/x-sisx-app)
538 ("vrm" . x-world/x-vrml)
539 ("vrml" . x-world/x-vrml)
540 ("wrl" . x-world/x-vrml))))
542 (define %file-ext-regexp
543 (make-regexp "(\\.(.*)|[~%])$"))
545 (define (file-extension file-name)
546 "Return the file extension for FILE-NAME, or #f if one is not
548 (and=> (regexp-exec %file-ext-regexp file-name)
550 (or (match:substring match 2)
551 (match:substring match 1)))))
553 (define (mime-type file-name)
554 "Guess the MIME type for FILE-NAME based upon its file extension."
555 (or (hash-ref %mime-types (file-extension file-name))