   [path]
   (-> path (relative-path) (strip-extensions) (str ".resource")))
 
-(defn file-mapping
+(defn mk-page-record
   [analyze-page root file]
   (let [path (.getPath file)]
     (fs/with-cwd root

  (str "/" (-> url (clojure.string/replace "index.resource" "") (strip-extensions))))

(defn add-page
  [site page-info]
  (assoc-in site (page-key (:url page-info)) (update-in page-info [:url] canonical-url)))

(defn page?
  "Helper predicate for testing whether an object is a map representing a page."
  [x] (contains? x :url))

(defn fixup-site
  [x]
  (clojure.walk/walk
   (fn [[k v]]
     (if (and (map? v) (not (page? v)))
       [k (fixup-site (assoc v
                             :all
                             (->> v (map last) (filter page?))))]
       [k v]))
   identity
   x))

(defn mapping->site
  "Convert a sequence of [path url] pairs to a map structure representing

  (let [root (fs/file root-path)]
    (->> (file-seq root)
         (filter page-file?)
         (map #(mk-page-record analyze-page root %)))))

(defn page-key
  "Convert a url relative to the root of the site into a sequence of its path parts
  ,omitting any extensions in the url. For use with Clojure's *-in functions."
  [url]
  (-> url (strip-extensions) (fs/split)))

