         allFiles.map(path.basename), dirs
 
       for file in allFiles
-        log.verbose "generate", "Loading plugin: %s", file
-        # Load file
-        plugin = require file
-
-        if 'filters' of plugin
-          for key, filter of plugin['filters']
-            log.silly "generate", "Found filter for %s", key
-            plugins.filters[key] = filter
-        if 'tags' of plugin
-          for key, tag of plugin['tags']
-            log.silly "generate", "Found tag for %s", key
-            plugins.tags[key] = tag
-        if 'converters' of plugin
-          for key, converter of plugin['converters']
-            log.silly "generate", "Found converter for %s", key
-            plugins.converters.push converter
-        if 'generators' of plugin
-          for key, generator of plugin['generators']
-            log.silly "generate", "Found generator for %s", key
-            plugins.generators.push generator
+        loadFileIntoPlugins file, plugins
 
       plugins
+
+loadFileIntoPlugins = (file, plugins) ->
+  log.verbose "generate", "Loading plugin: %s", file
+  plugin = require file
+
+  if 'filters' of plugin
+    for key, filter of plugin['filters']
+      log.silly "generate", "Found filter for %s", key
+      plugins.filters[key] = filter
+  if 'tags' of plugin
+    for key, tag of plugin['tags']
+      log.silly "generate", "Found tag for %s", key
+      plugins.tags[key] = tag
+  if 'converters' of plugin
+    for key, converter of plugin['converters']
+      log.silly "generate", "Found converter for %s", key
+      plugins.converters.push converter
+  if 'generators' of plugin
+    for key, generator of plugin['generators']
+      log.silly "generate", "Found generator for %s", key
+      plugins.generators.push generator


  { posts, others }

checkDirectories = (config, callback) ->
  # Check if source & destination directories are there
  async.series [
    (cb) -> fs.exists config.source, (exists) ->
      if exists then cb()
      else cb new Error "Source directory does not exist: #{config.source}"
    (cb) -> fs.exists config.destination, (exists) ->
      if exists
        fs.stat config.destination, (err, stat) ->
          if stat.isDirectory()
            cb()
          else
            cb new Error "Destination is not a directory: #{config.destination}"
      else
        fs.mkdirs config.destination, cb
  ], callback

loadBundledPlugins = (callback) ->
  loadPlugins([path.join __dirname, 'plugins'])
    .then (plugins) ->
      bundledPlugins = plugins

      for key, filter of tinyliquid.filters
        unless key of bundledPlugins.filters
          bundledPlugins.filters[key] = filter
      return

loadSitePlugins = (config) ->
  # Resolve directories relative to source
  dirs = config.plugins.map (dir) -> path.resolve config.source, dir
  # Only check directories that actually exist
  Q.allSettled(dirs.map (dir) -> Q.nfcall fs.stat, dir)
    .then (results) ->
      pluginDirs = []
      for result, i in results
        continue if result.state isnt 'fulfilled'
        pluginDirs.push dirs[i]

      loadPlugins pluginDirs

loadPlugins = (dirs) ->
  log.verbose "generate", "Looking for plugins in: %s", dirs.join ', '
