added hierarchic sidbar-pages & refactored namesspace.
This commit is contained in:
parent
d8f86e0414
commit
4f9ac917ae
3 changed files with 13 additions and 13 deletions
|
@ -15,7 +15,7 @@
|
||||||
[cryogen-core.sitemap :as sitemap]
|
[cryogen-core.sitemap :as sitemap]
|
||||||
[clojure.inspector :as inspector]
|
[clojure.inspector :as inspector]
|
||||||
[cryogen-core.toc :as toc]
|
[cryogen-core.toc :as toc]
|
||||||
[cryogen-core.navbar-model :as navbar-model])
|
[cryogen-core.hierarchic :as hierarchic])
|
||||||
(:import java.util.Locale))
|
(:import java.util.Locale))
|
||||||
|
|
||||||
(cache-off!)
|
(cache-off!)
|
||||||
|
@ -512,11 +512,11 @@
|
||||||
:latest-posts latest-posts
|
:latest-posts latest-posts
|
||||||
:navbar-pages (cond
|
:navbar-pages (cond
|
||||||
(= navbar-model :flat) navbar-pages
|
(= navbar-model :flat) navbar-pages
|
||||||
(= navbar-model :hierarchic) (navbar-model/build-nav-map navbar-pages)
|
(= navbar-model :hierarchic) (hierarchic/build-hierarchic-map navbar-pages)
|
||||||
)
|
)
|
||||||
:sidebar-pages (cond
|
:sidebar-pages (cond
|
||||||
(= navbar-model :flat) sidebar-pages
|
(= navbar-model :flat) sidebar-pages
|
||||||
;(= navbar-model :hierarchic) (build-nav-map navbar-pages)
|
(= navbar-model :hierarchic) (hierarchic/build-hierarchic-map sidebar-pages)
|
||||||
)
|
)
|
||||||
:home-page (if home-page
|
:home-page (if home-page
|
||||||
home-page
|
home-page
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(ns cryogen-core.navbar-model
|
(ns cryogen-core.hierarchic
|
||||||
(:require
|
(:require
|
||||||
[clojure.string :as s]))
|
[clojure.string :as s]))
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
(filter #(s/starts-with? (:uri %) clean-uri) pages))
|
(filter #(s/starts-with? (:uri %) clean-uri) pages))
|
||||||
)
|
)
|
||||||
|
|
||||||
(defn build-nav-map-level
|
(defn build-hierarchic-level
|
||||||
"builds one level of nav-map and recurs to next level."
|
"builds one level of nav-map and recurs to next level."
|
||||||
[parent-uri pages]
|
[parent-uri pages]
|
||||||
(let [current-level (+ 1 (uri-level parent-uri))
|
(let [current-level (+ 1 (uri-level parent-uri))
|
||||||
|
@ -32,12 +32,12 @@
|
||||||
(if (empty? child-pages)
|
(if (empty? child-pages)
|
||||||
page-on-level
|
page-on-level
|
||||||
(merge page-on-level
|
(merge page-on-level
|
||||||
{:children (build-nav-map-level (:uri page-on-level) child-pages)}))) pages-on-level))
|
{:children (build-hierarchic-level (:uri page-on-level) child-pages)}))) pages-on-level))
|
||||||
))
|
))
|
||||||
|
|
||||||
(defn build-nav-map
|
(defn build-hierarchic-map
|
||||||
"builds a nav-map from pages"
|
"builds a nav-map from pages"
|
||||||
[pages]
|
[pages]
|
||||||
(let [sorted-pages (sort-by :uri pages)]
|
(let [sorted-pages (sort-by :uri pages)]
|
||||||
(build-nav-map-level "/pages/" sorted-pages)
|
(build-hierarchic-level "/pages/" sorted-pages)
|
||||||
))
|
))
|
|
@ -1,7 +1,7 @@
|
||||||
(ns cryogen-core.navbar-model-test
|
(ns cryogen-core.hierarchic-test
|
||||||
(:require
|
(:require
|
||||||
[clojure.test :refer :all]
|
[clojure.test :refer :all]
|
||||||
[cryogen-core.navbar-model :as sut]))
|
[cryogen-core.hierarchic :as sut]))
|
||||||
|
|
||||||
(defn- page [uri page-index]
|
(defn- page [uri page-index]
|
||||||
{:uri uri
|
{:uri uri
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty))))
|
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty))))
|
||||||
))
|
))
|
||||||
|
|
||||||
(deftest test-navmap-pages
|
(deftest test-hierarchic-pages
|
||||||
(testing
|
(testing
|
||||||
"No pages or posts nothing to copy"
|
"No pages or posts nothing to copy"
|
||||||
(let [expected-clean [(enhanced-page
|
(let [expected-clean [(enhanced-page
|
||||||
|
@ -65,8 +65,8 @@
|
||||||
)]
|
)]
|
||||||
]
|
]
|
||||||
(is (= expected-clean
|
(is (= expected-clean
|
||||||
(sut/build-nav-map pages-clean)))
|
(sut/build-hierarchic-map pages-clean)))
|
||||||
(is (= expected-dirty
|
(is (= expected-dirty
|
||||||
(sut/build-nav-map pages-dirty)))
|
(sut/build-hierarchic-map pages-dirty)))
|
||||||
)
|
)
|
||||||
))
|
))
|
Loading…
Reference in a new issue