       # ...and now we've seen them all
       @push file for file in files
       flushCallback()
-
-navTree =
-  parent: null
-  children: {}
-  exists: no
-  title: null
-
-orderGen = 9999
-
-insertNavIntoTree = (relativePath, extension, title, order) ->
-  _path = path.resolve '/', relativePath
-    .replace /index\.[^/]+$/, ''              # index identified with directory
-    .replace /\.[^./]+$/, '.' + extension     # e.g. '.jade' -> '.html'
-    .split /([^/]*\/)/                        # e.g. '/a/b' -> ['/', 'a/', 'b']
-    .filter (element) -> element isnt ''
-  current = navTree
-  for element in _path
-    current = current.children[element] ?=   # recurse down, filling in missing
-      parent: current
-      children: {}
-      exists: no                             # for directories without an index
-      title: path.basename element.replace /\/?index[^/]*$/, ''
-        .toLowerCase()
-        .replace /\.[^.]*$/, ''                        # remove extension
-        .replace /(?:^|[-._])[a-z]/g, (first) ->
-          first.toUpperCase()                          # capitalize each word
-        .replace /[-._]/g, ' '                         # punctuation to spaces
-        .replace /^$/, '/'                             # root needs a title too
-      order: orderGen++
-  current.exists = yes             # if we're here, this resource *does* exist!
-  current.title = title ? current.title     # overwrite defaults with non-nulls
-  current.order = order ? current.order
-  navInContext current, [_path.join '']
 
 # Create the actual nav object that will be exposed to user code. This object
 # knows (and the objects that it creates, in turn, know) the context in which

   demoteTopIndex
###

path = require 'path'
webPath = require './web-path'
through = require 'through2'
  .obj

root = null
rootName = null

module.exports =
  ({sources, targets, titles, orders, skips, hrefExtension,
  demoteTopIndex}={}) ->
    # defaults -- the first five are just arrays of property names
    sources ?= ['data', 'frontMatter']
    targets ?= ['nav', 'data.nav']
    titles ?= ['short_title', 'title']
    orders ?= 'order'
    skips ?= 'skipThis'
    hrefExtension ?= 'html'
    demoteTopIndex ?= no
    # single options don't have to come wrapped in an Array

      get: ->
        (navInContext child, context.concat name for [child, name] in (
          [child, name] for name, child of nav.children)
            .sort ([a, ...], [b, ...]) -> a.order - b.order)
    siblings:
      enumerable: yes
      get: ->
