all things implemented - probably works
This commit is contained in:
parent
e9d1c1e194
commit
439ae6fba8
2 changed files with 64 additions and 22 deletions
|
@ -2,11 +2,21 @@
|
|||
(:require
|
||||
[clojure.string :as s]))
|
||||
|
||||
(defn- uri-level [uri]
|
||||
(count (s/split uri #"/")))
|
||||
(defn uri-level [uri]
|
||||
(- (count
|
||||
(s/split uri #"/"))
|
||||
1)
|
||||
)
|
||||
|
||||
(defn- filter-pages-for-uri [uri pages]
|
||||
(filter #(s/starts-with? (:uri %) uri) pages))
|
||||
(defn filter-pages-for-uri [uri pages]
|
||||
(let [html? (s/ends-with? uri ".html")
|
||||
clean? (s/ends-with? uri "/")
|
||||
clean-uri (cond
|
||||
html? (subs uri 0 (- (count uri) 5))
|
||||
clean? (subs uri 0 (- (count uri) 1))
|
||||
:default uri)]
|
||||
(filter #(s/starts-with? (:uri %) clean-uri) pages))
|
||||
)
|
||||
|
||||
(defn build-nav-map-level
|
||||
"builds one level of nav-map and recurs to next level."
|
||||
|
|
|
@ -13,28 +13,60 @@
|
|||
:content uri
|
||||
:page-index page-index
|
||||
:children children})
|
||||
|
||||
(def pages-clean [(page "/pages/nav1/" 0)
|
||||
(page "/pages/nav1/nav11/" 1)
|
||||
(page "/pages/nav1/nav13/" 3)
|
||||
(page "/pages/nav1/nav11/nav112/" 2)
|
||||
(page "/pages/nav1/nav12/" 2)
|
||||
(page "/pages/nav1/nav11/xnav111/" 1)
|
||||
])
|
||||
|
||||
(def pages-dirty [(page "/pages/nav1.html" 0)
|
||||
(page "/pages/nav1/nav11.html" 1)
|
||||
(page "/pages/nav1/nav13.html" 3)
|
||||
(page "/pages/nav1/nav11/nav112.html" 2)
|
||||
(page "/pages/nav1/nav12.html" 2)
|
||||
(page "/pages/nav1/nav11/xnav111.html" 1)
|
||||
])
|
||||
|
||||
(deftest test-uri-level
|
||||
(testing
|
||||
(is (= 2 (sut/uri-level "/pages/nav1/")))
|
||||
(is (= 2 (sut/uri-level "/pages/nav1.html")))
|
||||
))
|
||||
|
||||
(deftest test-filter-pages-for-uri
|
||||
(testing
|
||||
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1/" pages-clean))))
|
||||
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty))))
|
||||
))
|
||||
|
||||
(deftest test-navmap-pages
|
||||
(testing
|
||||
"No pages or posts nothing to copy"
|
||||
(let [pages [(page "/pages/nav1/" 0)
|
||||
(page "/pages/nav1/nav11/" 1)
|
||||
(page "/pages/nav1/nav13/" 3)
|
||||
(page "/pages/nav1/nav11/nav112/" 2)
|
||||
(page "/pages/nav1/nav12/" 2)
|
||||
(page "/pages/nav1/nav11/xnav111/" 1)
|
||||
]
|
||||
expected [(enhanced-page
|
||||
"/pages/nav1/" 0
|
||||
[(enhanced-page
|
||||
"/pages/nav1/nav11/" 1
|
||||
[(page "/pages/nav1/nav11/xnav111/" 1)
|
||||
(page "/pages/nav1/nav11/nav112/" 2)])
|
||||
(page "/pages/nav1/nav12/" 2)
|
||||
(page "/pages/nav1/nav13/" 3)]
|
||||
)]
|
||||
(let [expected-clean [(enhanced-page
|
||||
"/pages/nav1/" 0
|
||||
[(enhanced-page
|
||||
"/pages/nav1/nav11/" 1
|
||||
[(page "/pages/nav1/nav11/xnav111/" 1)
|
||||
(page "/pages/nav1/nav11/nav112/" 2)])
|
||||
(page "/pages/nav1/nav12/" 2)
|
||||
(page "/pages/nav1/nav13/" 3)]
|
||||
)]
|
||||
expected-dirty [(enhanced-page
|
||||
"/pages/nav1.html" 0
|
||||
[(enhanced-page
|
||||
"/pages/nav1/nav11.html" 1
|
||||
[(page "/pages/nav1/nav11/xnav111.html" 1)
|
||||
(page "/pages/nav1/nav11/nav112.html" 2)])
|
||||
(page "/pages/nav1/nav12.html" 2)
|
||||
(page "/pages/nav1/nav13.html" 3)]
|
||||
)]
|
||||
]
|
||||
(is (= expected
|
||||
(sut/build-nav-map pages)))
|
||||
(is (= expected-clean
|
||||
(sut/build-nav-map pages-clean)))
|
||||
(is (= expected-dirty
|
||||
(sut/build-nav-map pages-dirty)))
|
||||
)
|
||||
))
|
||||
|
|
Loading…
Reference in a new issue