compile hierarchic pages

This commit is contained in:
Michael Jerger 2017-03-12 10:33:50 +01:00
parent 6cf7b1a72b
commit e8d7069598
2 changed files with 23 additions and 22 deletions

View file

@ -251,7 +251,9 @@
:home false :home false
:servlet-context (cryogen-io/path "/" blog-prefix "/") :servlet-context (cryogen-io/path "/" blog-prefix "/")
:page page :page page
:uri uri})))))) :uri uri})))
(compile-pages params (:children page)))
))
(defn compile-posts (defn compile-posts
"Compiles all the posts into html and spits them out into the public folder" "Compiles all the posts into html and spits them out into the public folder"
@ -495,11 +497,15 @@
posts-by-tag (group-by-tags posts) posts-by-tag (group-by-tags posts)
posts (tag-posts posts config) posts (tag-posts posts config)
latest-posts (->> posts (take recent-posts) vec) latest-posts (->> posts (take recent-posts) vec)
pages (map klipsify (read-pages config)) klipsified-pages (map klipsify (read-pages config))
home-page (->> pages modelled-pages (cond
(= page-model :flat) klipsified-pages
(= page-model :hierarchic) (hierarchic/build-hierarchic-map klipsified-pages)
)
home-page (->> modelled-pages
(filter #(boolean (:home? %))) (filter #(boolean (:home? %)))
(first)) (first))
other-pages (->> pages other-pages (->> modelled-pages
(remove #{home-page}) (remove #{home-page})
(add-prev-next)) (add-prev-next))
params (merge config params (merge config
@ -508,10 +514,7 @@
:active-page "home" :active-page "home"
:tags (map (partial tag-info config) (keys posts-by-tag)) :tags (map (partial tag-info config) (keys posts-by-tag))
:latest-posts latest-posts :latest-posts latest-posts
:pages (cond :pages other-pages
(= page-model :flat) other-pages
(= page-model :hierarchic) (hierarchic/build-hierarchic-map other-pages)
)
:home-page (if home-page :home-page (if home-page
home-page home-page
(assoc (first latest-posts) :layout "home.html")) (assoc (first latest-posts) :layout "home.html"))
@ -523,8 +526,6 @@
(when debug? (when debug?
(println (blue "debug: page-model:")) (println (blue "debug: page-model:"))
(println "\t-->" (cyan page-model)) (println "\t-->" (cyan page-model))
(println (blue "debug: pages:"))
(println "\t-->" (cyan (-> params :pages)))
(println (blue "debug: home-page:")) (println (blue "debug: home-page:"))
(println "\t-->" (cyan (-> params :home-page))) (println "\t-->" (cyan (-> params :home-page)))
) )
@ -535,7 +536,7 @@
(println (blue "copying resources")) (println (blue "copying resources"))
(cryogen-io/copy-resources config) (cryogen-io/copy-resources config)
(copy-resources-from-markup-folders config) (copy-resources-from-markup-folders config)
(compile-pages params other-pages) (compile-pages params modelled-pages)
(compile-posts params posts) (compile-posts params posts)
(compile-tags params posts-by-tag) (compile-tags params posts-by-tag)
(compile-tags-page params) (compile-tags-page params)

View file

@ -19,7 +19,7 @@
) )
(defn build-hierarchic-level (defn build-hierarchic-level
"builds one level of nav-map and recurs to next level." "builds one level of hierarchic tree 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))
pages-of-parent (filter-pages-for-uri parent-uri pages) pages-of-parent (filter-pages-for-uri parent-uri pages)
@ -36,7 +36,7 @@
)) ))
(defn build-hierarchic-map (defn build-hierarchic-map
"builds a nav-map from pages" "builds a hierarchic tree from pages"
[pages] [pages]
(let [sorted-pages (sort-by :uri pages)] (let [sorted-pages (sort-by :uri pages)]
(build-hierarchic-level "/pages/" sorted-pages) (build-hierarchic-level "/pages/" sorted-pages)