Merge branch 'development'
This commit is contained in:
commit
c9ea1adc2e
3 changed files with 95 additions and 46 deletions
|
@ -491,7 +491,7 @@
|
|||
[]
|
||||
(println (green "compiling assets..."))
|
||||
(let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-dest keep-files ignored-files previews?
|
||||
author-root-uri theme debug? page-model]
|
||||
author-root-uri theme debug? page-model page-root-uri ]
|
||||
:as config} (read-config)
|
||||
posts (map klipsify (add-prev-next (read-posts config)))
|
||||
posts-by-tag (group-by-tags posts)
|
||||
|
@ -500,7 +500,7 @@
|
|||
klipsified-pages (map klipsify (read-pages config))
|
||||
modelled-pages (cond
|
||||
(= page-model :flat) klipsified-pages
|
||||
(= page-model :hierarchic) (hierarchic/build-hierarchic-map klipsified-pages)
|
||||
(= page-model :hierarchic) (hierarchic/build-hierarchic-map page-root-uri klipsified-pages)
|
||||
)
|
||||
home-page (->> modelled-pages
|
||||
(filter #(boolean (:home? %)))
|
||||
|
|
|
@ -2,6 +2,23 @@
|
|||
(:require
|
||||
[clojure.string :as s]))
|
||||
|
||||
(defn normalized-page-root-uri [page-root-uri]
|
||||
(cond
|
||||
(= "" page-root-uri) ""
|
||||
(and
|
||||
(s/starts-with? page-root-uri "/")
|
||||
(s/ends-with? page-root-uri "/")) page-root-uri
|
||||
(and
|
||||
(s/starts-with? page-root-uri "/")
|
||||
(not (s/ends-with? page-root-uri "/"))) (str page-root-uri "/")
|
||||
(and
|
||||
(not (s/starts-with? page-root-uri "/"))
|
||||
(s/ends-with? page-root-uri "/")) (str "/" page-root-uri)
|
||||
(and
|
||||
(not (s/starts-with? page-root-uri "/"))
|
||||
(not (s/ends-with? page-root-uri "/"))) (str "/" page-root-uri "/"))
|
||||
)
|
||||
|
||||
(defn uri-level [uri]
|
||||
(- (count
|
||||
(s/split uri #"/"))
|
||||
|
@ -37,7 +54,7 @@
|
|||
|
||||
(defn build-hierarchic-map
|
||||
"builds a hierarchic tree from pages"
|
||||
[pages]
|
||||
[page-root-uri pages]
|
||||
(let [sorted-pages (sort-by :uri pages)]
|
||||
(build-hierarchic-level "/pages/" sorted-pages)
|
||||
(build-hierarchic-level (normalized-page-root-uri page-root-uri) sorted-pages)
|
||||
))
|
||||
|
|
|
@ -14,13 +14,38 @@
|
|||
: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)
|
||||
])
|
||||
(deftest test-normalized-page-root-uri
|
||||
(testing
|
||||
(is (= "" (sut/normalized-page-root-uri "")))
|
||||
(is (= "/root/" (sut/normalized-page-root-uri "root")))
|
||||
(is (= "/root/" (sut/normalized-page-root-uri "/root")))
|
||||
(is (= "/root/" (sut/normalized-page-root-uri "root/")))
|
||||
(is (= "/root/" (sut/normalized-page-root-uri "/root/")))
|
||||
))
|
||||
|
||||
(deftest test-uri-level
|
||||
(testing
|
||||
(is (= 2 (sut/uri-level "/pages/nav1/")))
|
||||
(is (= 2 (sut/uri-level "/pages/nav1.html")))
|
||||
))
|
||||
|
||||
(def pages-clean-1 [(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 expected-clean-1 [(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)]
|
||||
)])
|
||||
|
||||
(def pages-dirty [(page "/pages/nav1.html" 0)
|
||||
(page "/pages/nav1/nav11.html" 1)
|
||||
|
@ -30,43 +55,50 @@
|
|||
(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")))
|
||||
))
|
||||
(def 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)]
|
||||
)])
|
||||
|
||||
(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))))
|
||||
))
|
||||
(def pages-clean-2 [(page "/pages/1/" 0)
|
||||
(page "/pages/2/" 1)
|
||||
(page "/pages/2/22/" 0)])
|
||||
|
||||
(def expected-clean-2 [(page "/pages/1/" 0)
|
||||
(enhanced-page
|
||||
"/pages/2/" 1
|
||||
[(page "/pages/2/22/" 0)])])
|
||||
|
||||
(def pages-clean-3 [(page "/1/" 0)
|
||||
(page "/2/" 1)
|
||||
(page "/2/22/" 0)])
|
||||
|
||||
(def expected-clean-3 [(page "/1/" 0)
|
||||
(enhanced-page
|
||||
"/2/" 1
|
||||
[(page "/2/22/" 0)])])
|
||||
|
||||
(deftest test-hierarchic-pages
|
||||
(testing
|
||||
"No pages or posts nothing to copy"
|
||||
(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-clean
|
||||
(sut/build-hierarchic-map pages-clean)))
|
||||
"hierarchic expectations"
|
||||
(is (= expected-clean-1
|
||||
(sut/build-hierarchic-map "pages" pages-clean-1)))
|
||||
(is (= expected-dirty
|
||||
(sut/build-hierarchic-map pages-dirty)))
|
||||
(sut/build-hierarchic-map "pages" pages-dirty)))
|
||||
(is (= expected-clean-2
|
||||
(sut/build-hierarchic-map "pages" pages-clean-2)))
|
||||
(is (= expected-clean-3
|
||||
(sut/build-hierarchic-map "" pages-clean-3)))
|
||||
)
|
||||
)
|
||||
|
||||
(deftest test-filter-pages-for-uri
|
||||
(testing
|
||||
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1/" pages-clean-1))))
|
||||
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty))))
|
||||
))
|
Loading…
Reference in a new issue