Merge branch 'development'

This commit is contained in:
Michael Jerger 2017-03-22 08:06:42 +01:00
commit c9ea1adc2e
3 changed files with 95 additions and 46 deletions

View file

@ -491,7 +491,7 @@
[] []
(println (green "compiling assets...")) (println (green "compiling assets..."))
(let [{:keys [^String site-url blog-prefix rss-name recent-posts sass-dest keep-files ignored-files previews? (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) :as config} (read-config)
posts (map klipsify (add-prev-next (read-posts config))) posts (map klipsify (add-prev-next (read-posts config)))
posts-by-tag (group-by-tags posts) posts-by-tag (group-by-tags posts)
@ -500,7 +500,7 @@
klipsified-pages (map klipsify (read-pages config)) klipsified-pages (map klipsify (read-pages config))
modelled-pages (cond modelled-pages (cond
(= page-model :flat) klipsified-pages (= 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 home-page (->> modelled-pages
(filter #(boolean (:home? %))) (filter #(boolean (:home? %)))

View file

@ -2,6 +2,23 @@
(:require (:require
[clojure.string :as s])) [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] (defn uri-level [uri]
(- (count (- (count
(s/split uri #"/")) (s/split uri #"/"))
@ -37,7 +54,7 @@
(defn build-hierarchic-map (defn build-hierarchic-map
"builds a hierarchic tree from pages" "builds a hierarchic tree from pages"
[pages] [page-root-uri pages]
(let [sorted-pages (sort-by :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)
)) ))

View file

@ -13,14 +13,39 @@
:content uri :content uri
:page-index page-index :page-index page-index
:children children}) :children children})
(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/")))
))
(def pages-clean [(page "/pages/nav1/" 0) (deftest test-uri-level
(page "/pages/nav1/nav11/" 1) (testing
(page "/pages/nav1/nav13/" 3) (is (= 2 (sut/uri-level "/pages/nav1/")))
(page "/pages/nav1/nav11/nav112/" 2) (is (= 2 (sut/uri-level "/pages/nav1.html")))
(page "/pages/nav1/nav12/" 2) ))
(page "/pages/nav1/nav11/xnav111/" 1)
]) (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) (def pages-dirty [(page "/pages/nav1.html" 0)
(page "/pages/nav1/nav11.html" 1) (page "/pages/nav1/nav11.html" 1)
@ -29,44 +54,51 @@
(page "/pages/nav1/nav12.html" 2) (page "/pages/nav1/nav12.html" 2)
(page "/pages/nav1/nav11/xnav111.html" 1) (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 (def expected-dirty [(enhanced-page
(testing "/pages/nav1.html" 0
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1/" pages-clean)))) [(enhanced-page
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty)))) "/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)]
)])
(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 (deftest test-hierarchic-pages
(testing (testing
"No pages or posts nothing to copy" "hierarchic expectations"
(let [expected-clean [(enhanced-page (is (= expected-clean-1
"/pages/nav1/" 0 (sut/build-hierarchic-map "pages" pages-clean-1)))
[(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)))
(is (= expected-dirty (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))))
))