Skip to content

Instantly share code, notes, and snippets.

@grantmacken
Last active October 6, 2015 23:20
Show Gist options
  • Save grantmacken/2659def7a17452172d85 to your computer and use it in GitHub Desktop.
Save grantmacken/2659def7a17452172d85 to your computer and use it in GitHub Desktop.
Make function get mime-type using #existdb mime-types file
# makes a shell call to node and uses cheerio to extract mimetype from
# passed in file name
# depends on cheerio node_module in reachable node path
getMimeType = $(shell node -pe "\
fs = require('fs');\
re = /$1/;\
n = require('cheerio').load(fs.readFileSync('$(EXIST_HOME)/mime-types.xml'),\
{ normalizeWhitespace: true, xmlMode: true});\
n('extensions').filter(function(i, el){\
return re.test(n(this).text());\
}).parent().attr('name');\
")
# Used in make target like below
# @echo $(call getMimeType,$(suffix $(notdir $<)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment