respect :page-index order for navmap

This commit is contained in:
Michael Jerger 2017-01-05 17:10:07 +01:00
parent 0d4a9c90f6
commit 1ea38c5b84
2 changed files with 24 additions and 21 deletions

View file

@ -231,12 +231,13 @@
pages-on-level (filter #(= current-level (uri-level (:uri %))) pages-of-parent) pages-on-level (filter #(= current-level (uri-level (:uri %))) pages-of-parent)
pages-on-child-level (filter #(< current-level (uri-level (:uri %))) pages-of-parent) pages-on-child-level (filter #(< current-level (uri-level (:uri %))) pages-of-parent)
] ]
(sort-by :page-index
(map #(let [page-on-level % (map #(let [page-on-level %
child-pages (filter-pages-for-uri (:uri page-on-level) pages-on-child-level)] child-pages (filter-pages-for-uri (:uri page-on-level) pages-on-child-level)]
(if (empty? child-pages) (if (empty? child-pages)
page-on-level page-on-level
(merge page-on-level (merge page-on-level
{:navmap-children (build-nav-map-level (:uri page-on-level) child-pages)}))) pages-on-level) {:navmap-children (build-nav-map-level (:uri page-on-level) child-pages)}))) pages-on-level))
)) ))
(defn build-nav-map (defn build-nav-map

View file

@ -118,31 +118,33 @@ and more content.
(reset-resources)) (reset-resources))
(defn- page [uri] (defn- page [uri page-index]
{:navmap? true, :uri uri :content uri}) {:navmap? true, :uri uri :content uri :page-index page-index})
(defn- enhanced-page [uri children] (defn- enhanced-page [uri page-index children]
{:navmap? true, :uri uri :content uri {:navmap? true, :uri uri :content uri
:page-index page-index
:navmap-children children}) :navmap-children children})
(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 [{:navmap? false, :content "1"} (let [pages [{:navmap? false, :content "1"}
(page "/pages/nav1/") (page "/pages/nav1/" 0)
(page "/pages/nav1/nav11/") (page "/pages/nav1/nav11/" 1)
(page "/pages/nav1/nav12/") (page "/pages/nav1/nav13/" 3)
(page "/pages/nav1/nav13/") (page "/pages/nav1/nav11/nav112/" 2)
(page "/pages/nav1/nav11/nav111/") (page "/pages/nav1/nav12/" 2)
(page "/pages/nav1/nav11/nav112/")] (page "/pages/nav1/nav11/xnav111/" 1)
]
expected [(enhanced-page expected [(enhanced-page
"/pages/nav1/" "/pages/nav1/" 0
[(enhanced-page [(enhanced-page
"/pages/nav1/nav11/" "/pages/nav1/nav11/" 1
[(page "/pages/nav1/nav11/nav111/") [(page "/pages/nav1/nav11/xnav111/" 1)
(page "/pages/nav1/nav11/nav112/")]) (page "/pages/nav1/nav11/nav112/" 2)])
(page "/pages/nav1/nav12/") (page "/pages/nav1/nav12/" 2)
(page "/pages/nav1/nav13/")] (page "/pages/nav1/nav13/" 3)]
)] )]
] ]
(is (= expected (is (= expected