all things implemented - probably works

This commit is contained in:
Michael Jerger 2017-02-08 20:09:01 +01:00
parent e9d1c1e194
commit 439ae6fba8
2 changed files with 64 additions and 22 deletions

View file

@ -2,11 +2,21 @@
(:require (:require
[clojure.string :as s])) [clojure.string :as s]))
(defn- uri-level [uri] (defn uri-level [uri]
(count (s/split uri #"/"))) (- (count
(s/split uri #"/"))
1)
)
(defn- filter-pages-for-uri [uri pages] (defn filter-pages-for-uri [uri pages]
(filter #(s/starts-with? (: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 (defn build-nav-map-level
"builds one level of nav-map and recurs to next level." "builds one level of nav-map and recurs to next level."

View file

@ -13,28 +13,60 @@
:content uri :content uri
:page-index page-index :page-index page-index
:children children}) :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 (deftest test-navmap-pages
(testing (testing
"No pages or posts nothing to copy" "No pages or posts nothing to copy"
(let [pages [(page "/pages/nav1/" 0) (let [expected-clean [(enhanced-page
(page "/pages/nav1/nav11/" 1) "/pages/nav1/" 0
(page "/pages/nav1/nav13/" 3) [(enhanced-page
(page "/pages/nav1/nav11/nav112/" 2) "/pages/nav1/nav11/" 1
(page "/pages/nav1/nav12/" 2) [(page "/pages/nav1/nav11/xnav111/" 1)
(page "/pages/nav1/nav11/xnav111/" 1) (page "/pages/nav1/nav11/nav112/" 2)])
] (page "/pages/nav1/nav12/" 2)
expected [(enhanced-page (page "/pages/nav1/nav13/" 3)]
"/pages/nav1/" 0 )]
[(enhanced-page expected-dirty [(enhanced-page
"/pages/nav1/nav11/" 1 "/pages/nav1.html" 0
[(page "/pages/nav1/nav11/xnav111/" 1) [(enhanced-page
(page "/pages/nav1/nav11/nav112/" 2)]) "/pages/nav1/nav11.html" 1
(page "/pages/nav1/nav12/" 2) [(page "/pages/nav1/nav11/xnav111.html" 1)
(page "/pages/nav1/nav13/" 3)] (page "/pages/nav1/nav11/nav112.html" 2)])
)] (page "/pages/nav1/nav12.html" 2)
(page "/pages/nav1/nav13.html" 3)]
)]
] ]
(is (= expected (is (= expected-clean
(sut/build-nav-map pages))) (sut/build-nav-map pages-clean)))
(is (= expected-dirty
(sut/build-nav-map pages-dirty)))
) )
)) ))