create dirs from md works
This commit is contained in:
parent
399ed2d8ec
commit
8ecdb8c3c6
14 changed files with 338 additions and 306 deletions
|
@ -28,7 +28,7 @@
|
|||
:uri Uri
|
||||
:file File
|
||||
:source-type SourceType
|
||||
:resource-type ResourceType })
|
||||
:resource-type ResourceType})
|
||||
|
||||
(def public "resources/public")
|
||||
|
||||
|
@ -169,8 +169,7 @@
|
|||
(get-resources-recursive
|
||||
fs-prefix base-path paths
|
||||
:from-cp from-cp
|
||||
:from-fs from-fs))
|
||||
)
|
||||
:from-fs from-fs)))
|
||||
|
||||
; TODO: Add files to keep
|
||||
(s/defn delete-resource-recursive!
|
||||
|
@ -191,18 +190,18 @@
|
|||
]
|
||||
(let [resource-paths
|
||||
(get-resource-paths-recursive fs-prefix base-path source-paths)]
|
||||
(if (empty? resource-paths)
|
||||
(if (empty? resource-paths)
|
||||
(throw (IllegalArgumentException. (str "resource " resource-paths ", "
|
||||
source-paths " not found")))
|
||||
(doseq [resource-path resource-paths]
|
||||
(let [target-file (io/file target-path resource-path)
|
||||
source-file (io/file (file-from-cp-or-fs
|
||||
fs-prefix
|
||||
base-path
|
||||
resource-path))]
|
||||
(io/make-parents target-file)
|
||||
(when (.isFile source-file)
|
||||
(io/copy source-file target-file)))))))
|
||||
(doseq [resource-path resource-paths]
|
||||
(let [target-file (io/file target-path resource-path)
|
||||
source-file (io/file (file-from-cp-or-fs
|
||||
fs-prefix
|
||||
base-path
|
||||
resource-path))]
|
||||
(io/make-parents target-file)
|
||||
(when (.isFile source-file)
|
||||
(io/copy source-file target-file)))))))
|
||||
|
||||
(defn copy-resources-from-user!
|
||||
[fs-prefix resources target-path ignore-patterns]
|
||||
|
@ -217,3 +216,32 @@
|
|||
target-path ignore-patterns)
|
||||
(copy-resources! fs-prefix (str theme-path "/html") ["404.html"]
|
||||
target-path ignore-patterns)))
|
||||
|
||||
(defn distinct-resources-by-path
|
||||
[resources]
|
||||
(loop [paths (set (map :path resources))
|
||||
resources resources
|
||||
acc []]
|
||||
(cond (empty? resources) acc
|
||||
(contains? paths (:path (first resources))) (recur (disj paths (:path (first resources)))
|
||||
(rest resources)
|
||||
(conj acc (first resources)))
|
||||
:else (recur paths (rest resources) acc))))
|
||||
|
||||
(defn get-distinct-markup-dirs
|
||||
[fs-prefix posts pages ignore-patterns]
|
||||
(let [base-path "templates/md"
|
||||
resources (get-resources-recursive
|
||||
fs-prefix base-path [pages posts])
|
||||
filtered-resources (->> (filter #(= (:resource-type %) :dir) resources)
|
||||
(distinct-resources-by-path))]
|
||||
filtered-resources))
|
||||
|
||||
(defn create-dirs-from-markup-folders!
|
||||
"Copy resources from markup folders. This does not copy the markup entries."
|
||||
[fs-prefix posts pages target-path ignore-patterns]
|
||||
(let [resources (get-distinct-markup-dirs fs-prefix posts pages
|
||||
ignore-patterns)]
|
||||
(doseq [resource resources]
|
||||
(io/make-parents (io/file (str target-path "/" (:path resource))))
|
||||
(.mkdir (io/file (str target-path "/" (:path resource)))))))
|
||||
|
|
|
@ -494,37 +494,37 @@
|
|||
author-root-uri theme debug? page-model
|
||||
page-root-uri resources]
|
||||
:as config} (read-config)
|
||||
posts (map klipsify (add-prev-next (read-posts config)))
|
||||
posts-by-tag (group-by-tags posts)
|
||||
posts (tag-posts posts config)
|
||||
latest-posts (->> posts (take recent-posts) vec)
|
||||
klipsified-pages (map klipsify (read-pages config))
|
||||
modelled-pages (cond
|
||||
(= page-model :flat) klipsified-pages
|
||||
(= page-model :hierarchic) (hierarchic/build-hierarchic-map page-root-uri klipsified-pages))
|
||||
home-page (->> modelled-pages
|
||||
(filter #(boolean (:home? %)))
|
||||
(first))
|
||||
other-pages (->> modelled-pages
|
||||
(remove #{home-page})
|
||||
(add-prev-next))
|
||||
params (merge config
|
||||
{:today (java.util.Date.)
|
||||
:title (:site-title config)
|
||||
:active-page "home"
|
||||
:tags (map (partial tag-info config) (keys posts-by-tag))
|
||||
:latest-posts latest-posts
|
||||
:pages other-pages
|
||||
:home-page (if home-page
|
||||
home-page
|
||||
(assoc (first latest-posts) :layout "home.html"))
|
||||
:archives-uri (page-uri "archives.html" config)
|
||||
:index-uri (page-uri "index.html" config)
|
||||
:tags-uri (page-uri "tags.html" config)
|
||||
:rss-uri (cryogen-io/path "/" blog-prefix rss-name)
|
||||
:site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)})
|
||||
file-resource-path (str "file:resources/templates/themes/" theme)
|
||||
classpath-resource-path (str "templates/themes/" theme)]
|
||||
posts (map klipsify (add-prev-next (read-posts config)))
|
||||
posts-by-tag (group-by-tags posts)
|
||||
posts (tag-posts posts config)
|
||||
latest-posts (->> posts (take recent-posts) vec)
|
||||
klipsified-pages (map klipsify (read-pages config))
|
||||
modelled-pages (cond
|
||||
(= page-model :flat) klipsified-pages
|
||||
(= page-model :hierarchic) (hierarchic/build-hierarchic-map page-root-uri klipsified-pages))
|
||||
home-page (->> modelled-pages
|
||||
(filter #(boolean (:home? %)))
|
||||
(first))
|
||||
other-pages (->> modelled-pages
|
||||
(remove #{home-page})
|
||||
(add-prev-next))
|
||||
params (merge config
|
||||
{:today (java.util.Date.)
|
||||
:title (:site-title config)
|
||||
:active-page "home"
|
||||
:tags (map (partial tag-info config) (keys posts-by-tag))
|
||||
:latest-posts latest-posts
|
||||
:pages other-pages
|
||||
:home-page (if home-page
|
||||
home-page
|
||||
(assoc (first latest-posts) :layout "home.html"))
|
||||
:archives-uri (page-uri "archives.html" config)
|
||||
:index-uri (page-uri "index.html" config)
|
||||
:tags-uri (page-uri "tags.html" config)
|
||||
:rss-uri (cryogen-io/path "/" blog-prefix rss-name)
|
||||
:site-url (if (.endsWith site-url "/") (.substring site-url 0 (dec (count site-url))) site-url)})
|
||||
file-resource-path (str "file:resources/templates/themes/" theme)
|
||||
classpath-resource-path (str "templates/themes/" theme)]
|
||||
(when debug?
|
||||
(println (blue "debug: page-model:"))
|
||||
(println "\t-->" (cyan page-model))
|
||||
|
@ -548,7 +548,12 @@
|
|||
ignored-files)
|
||||
;TODO: replace this
|
||||
; Nur directories kopieren
|
||||
(copy-resources-from-markup-folders config)
|
||||
;(copy-resources-from-markup-folders config)
|
||||
(cp-io/create-dirs-from-markup-folders! "resources/"
|
||||
(:posts config)
|
||||
(:pages config)
|
||||
(cp-io/path "resources/public" blog-prefix)
|
||||
ignored-files)
|
||||
(compile-pages params modelled-pages)
|
||||
(compile-posts params posts)
|
||||
(compile-tags params posts-by-tag)
|
||||
|
|
|
@ -1,29 +1,27 @@
|
|||
(ns cryogen-core.hierarchic
|
||||
(: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
|
||||
(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 "/")
|
||||
(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)
|
||||
(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 "/"))
|
||||
)
|
||||
(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 #"/"))
|
||||
1)
|
||||
)
|
||||
(s/split uri #"/"))
|
||||
1))
|
||||
|
||||
(defn filter-pages-for-uri [uri pages]
|
||||
(let [html? (s/ends-with? uri ".html")
|
||||
|
@ -32,8 +30,7 @@
|
|||
html? (subs uri 0 (- (count uri) 5))
|
||||
clean? (subs uri 0 (- (count uri) 1))
|
||||
:default uri)]
|
||||
(filter #(s/starts-with? (:uri %) clean-uri) pages))
|
||||
)
|
||||
(filter #(s/starts-with? (:uri %) clean-uri) pages)))
|
||||
|
||||
(defn build-hierarchic-level
|
||||
"builds one level of hierarchic tree recurs to next level."
|
||||
|
@ -41,20 +38,17 @@
|
|||
(let [current-level (+ 1 (uri-level parent-uri))
|
||||
pages-of-parent (filter-pages-for-uri parent-uri pages)
|
||||
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 %
|
||||
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)
|
||||
page-on-level
|
||||
(merge page-on-level
|
||||
{:children (build-hierarchic-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-hierarchic-map
|
||||
"builds a hierarchic tree from pages"
|
||||
[page-root-uri pages]
|
||||
(let [sorted-pages (sort-by :uri pages)]
|
||||
(build-hierarchic-level (normalized-page-root-uri page-root-uri) sorted-pages)
|
||||
))
|
||||
(build-hierarchic-level (normalized-page-root-uri page-root-uri) sorted-pages)))
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
[config]
|
||||
(let [theme-path (str "themes/" (:theme config))]
|
||||
(copy-resources
|
||||
(merge config
|
||||
{:resources [(str theme-path "/css")
|
||||
(str theme-path "/js")
|
||||
(str theme-path "/html/404.html")]}))))
|
||||
(merge config
|
||||
{:resources [(str theme-path "/css")
|
||||
(str theme-path "/js")
|
||||
(str theme-path "/html/404.html")]}))))
|
||||
|
|
|
@ -62,9 +62,9 @@
|
|||
[html settings]
|
||||
(letfn [(tag [h clas]
|
||||
(enlive/sniptest h
|
||||
[(keyword (str "code" clas))]
|
||||
(fn [x]
|
||||
(update-in x [:attrs :class] #(str % " nohighlight")))))]
|
||||
[(keyword (str "code" clas))]
|
||||
(fn [x]
|
||||
(update-in x [:attrs :class] #(str % " nohighlight")))))]
|
||||
(reduce tag html (eval-classes settings))))
|
||||
|
||||
(def defaults
|
||||
|
|
|
@ -4,30 +4,29 @@
|
|||
[cryogen-core.io :as cryogen-io])
|
||||
(:import java.util.Date))
|
||||
|
||||
|
||||
(defn posts-to-items [^String site-url posts]
|
||||
(map
|
||||
(fn [{:keys [uri title content date enclosure author description]}]
|
||||
(let [link (str (if (.endsWith site-url "/") (apply str (butlast site-url)) site-url) uri)
|
||||
enclosure (if (nil? enclosure) "" enclosure)]
|
||||
{:guid link
|
||||
:link link
|
||||
:title title
|
||||
:description (or description content)
|
||||
:author author
|
||||
:enclosure enclosure
|
||||
:pubDate date}))
|
||||
posts))
|
||||
(fn [{:keys [uri title content date enclosure author description]}]
|
||||
(let [link (str (if (.endsWith site-url "/") (apply str (butlast site-url)) site-url) uri)
|
||||
enclosure (if (nil? enclosure) "" enclosure)]
|
||||
{:guid link
|
||||
:link link
|
||||
:title title
|
||||
:description (or description content)
|
||||
:author author
|
||||
:enclosure enclosure
|
||||
:pubDate date}))
|
||||
posts))
|
||||
|
||||
(defn make-channel [config posts]
|
||||
(apply
|
||||
(partial rss/channel-xml
|
||||
false
|
||||
{:title (:site-title config)
|
||||
:link (:site-url config)
|
||||
:description (:description config)
|
||||
:lastBuildDate (Date.)})
|
||||
(posts-to-items (:site-url config) posts)))
|
||||
(partial rss/channel-xml
|
||||
false
|
||||
{:title (:site-title config)
|
||||
:link (:site-url config)
|
||||
:description (:description config)
|
||||
:lastBuildDate (Date.)})
|
||||
(posts-to-items (:site-url config) posts)))
|
||||
|
||||
(defn make-filtered-channels [{:keys [rss-filters blog-prefix] :as config} posts-by-tag]
|
||||
(doseq [filter rss-filters]
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
(defn generate [site-url ignored-files]
|
||||
(with-out-str
|
||||
(emit
|
||||
{:tag :urlset
|
||||
:attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
||||
:content
|
||||
(for [^java.io.File f (cryogen-io/find-assets "public" ".html" ignored-files)]
|
||||
{:tag :url
|
||||
:content
|
||||
[{:tag :loc
|
||||
:content [(str site-url (loc f))]}
|
||||
{:tag :lastmod
|
||||
:content [(-> f (.lastModified) (Date.) format-date)]}]})})))
|
||||
{:tag :urlset
|
||||
:attrs {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
||||
:content
|
||||
(for [^java.io.File f (cryogen-io/find-assets "public" ".html" ignored-files)]
|
||||
{:tag :url
|
||||
:content
|
||||
[{:tag :loc
|
||||
:content [(str site-url (loc f))]}
|
||||
{:tag :lastmod
|
||||
:content [(-> f (.lastModified) (Date.) format-date)]}]})})))
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
headings."
|
||||
[content]
|
||||
(reduce
|
||||
(fn [headings {:keys [tag attrs content] :as elm}]
|
||||
(if (some #{tag} _h)
|
||||
(conj headings elm)
|
||||
(if-let [more-headings (get-headings content)]
|
||||
(into headings more-headings)
|
||||
headings)))
|
||||
[] content))
|
||||
(fn [headings {:keys [tag attrs content] :as elm}]
|
||||
(if (some #{tag} _h)
|
||||
(conj headings elm)
|
||||
(if-let [more-headings (get-headings content)]
|
||||
(into headings more-headings)
|
||||
headings)))
|
||||
[] content))
|
||||
|
||||
(defn- zip-toc-tree-to-insertion-point
|
||||
"Given a toc-tree zipper and a header level, navigate
|
||||
|
@ -46,25 +46,24 @@
|
|||
and return it."
|
||||
[headings]
|
||||
(loop [zp (z/zipper
|
||||
map?
|
||||
:children
|
||||
(fn [node children] (assoc node :children (apply vector children)))
|
||||
{:value :root :children []})
|
||||
map?
|
||||
:children
|
||||
(fn [node children] (assoc node :children (apply vector children)))
|
||||
{:value :root :children []})
|
||||
items headings]
|
||||
(if-let [{tag :tag {id :id} :attrs [{{name :name} :attrs} title :as htext] :content} (first items)]
|
||||
(let [anchor (or id name)]
|
||||
(if (nil? anchor)
|
||||
(recur zp (rest items))
|
||||
(recur (insert-toc-tree-entry zp
|
||||
{:tag tag
|
||||
:anchor anchor
|
||||
:text (or
|
||||
(if (string? title) title (-> title :content first))
|
||||
(first htext))})
|
||||
{:tag tag
|
||||
:anchor anchor
|
||||
:text (or
|
||||
(if (string? title) title (-> title :content first))
|
||||
(first htext))})
|
||||
(rest items))))
|
||||
(z/root zp))))
|
||||
|
||||
|
||||
(defn- make-toc-entry
|
||||
"Given an anchor link and some text, construct a toc entry
|
||||
consisting of link to the anchor using the given text, wrapped
|
||||
|
@ -73,7 +72,6 @@
|
|||
(when (and anchor text)
|
||||
[:li [:a {:href (str "#" anchor)} text]]))
|
||||
|
||||
|
||||
(defn- build-toc
|
||||
"Given the root of a toc tree and either :ol or :ul,
|
||||
generate the table of contents and return it as a hiccup tree."
|
||||
|
@ -86,9 +84,9 @@
|
|||
; Create hiccup sequence of :ol/:ul tag and sequence of :li tags
|
||||
(if (seq children)
|
||||
(let [sublist [first-list-open (map build-toc children
|
||||
(repeat list-open)
|
||||
(repeat :outer-list?)
|
||||
(repeat false))]]
|
||||
(repeat list-open)
|
||||
(repeat :outer-list?)
|
||||
(repeat false))]]
|
||||
(if-let [li li] ; The root element has nothing so ignore it
|
||||
(seq [li sublist]) ; Use seq to lazily concat the li with the sublists
|
||||
sublist))
|
||||
|
@ -105,8 +103,8 @@
|
|||
[html & {:keys [list-type] :or {list-type :ol}}]
|
||||
(let [list-type (if (true? list-type) :ol list-type)]
|
||||
(-> html
|
||||
(enlive/html-snippet)
|
||||
(get-headings)
|
||||
(build-toc-tree)
|
||||
(build-toc list-type)
|
||||
(hiccup/html))))
|
||||
(enlive/html-snippet)
|
||||
(get-headings)
|
||||
(build-toc-tree)
|
||||
(build-toc list-type)
|
||||
(hiccup/html))))
|
||||
|
|
0
test-resources/templates/md/test_pages/home/.gitkeep
Normal file
0
test-resources/templates/md/test_pages/home/.gitkeep
Normal file
0
test-resources/templates/md/test_posts/home/.gitkeep
Normal file
0
test-resources/templates/md/test_posts/home/.gitkeep
Normal file
|
@ -77,54 +77,73 @@
|
|||
(map filter-object
|
||||
(sut/get-resources-recursive
|
||||
"" "templates/themes/bootstrap4-test" ["js/dummy.js"]))))
|
||||
(is (=
|
||||
["js/subdir"
|
||||
"js/subdir/test.js"
|
||||
"js/subdir/subdummy.js"]
|
||||
(map #(:path %)
|
||||
(sut/get-resources-recursive
|
||||
"" "templates/themes/bootstrap4-test" ["js/subdir"])))))
|
||||
|
||||
(deftest test-get-resource-paths-recursive
|
||||
(is (=
|
||||
[]
|
||||
(sut/get-resource-paths-recursive "" "templates/themes/bootstrap4-test" ["not-existing"])))
|
||||
(is (=
|
||||
["js/dummy.js"]
|
||||
(sut/get-resource-paths-recursive
|
||||
"" "templates/themes/bootstrap4-test" ["js/dummy.js"])))
|
||||
(is (=
|
||||
[]
|
||||
(sut/get-resource-paths-recursive
|
||||
"" "templates/themes/bootstrap4-test" ["js/dummy.js"]
|
||||
:from-cp false)))
|
||||
(sut/get-resources-recursive
|
||||
"" "templates/themes/bootstrap4-test" ["js/dummy.js"] :from-cp false)))
|
||||
(is (=
|
||||
["js/subdir"
|
||||
"js/subdir/test.js"
|
||||
"js/subdir/subdummy.js"]
|
||||
(sut/get-resource-paths-recursive
|
||||
"" "templates/themes/bootstrap4-test" ["js/subdir"])))
|
||||
"js/subdir/subdummy.js"
|
||||
"js/subdir/test.js"]
|
||||
(sort (map :path
|
||||
(sut/get-resources-recursive
|
||||
"" "templates/themes/bootstrap4-test" ["js/subdir"])))))
|
||||
(is (=
|
||||
["."
|
||||
"./css"
|
||||
"./css/dummy.css"
|
||||
"./js"
|
||||
"./js/subdir"
|
||||
"./js/subdir/test.js"
|
||||
"./js/subdir/subdummy.js"
|
||||
"./js/dummy.js"
|
||||
"./html"
|
||||
"./html/403.html"
|
||||
"./html/404.html"]
|
||||
(sut/get-resource-paths-recursive "" "templates/themes/bootstrap4-test" ["."])))
|
||||
)
|
||||
"./html/404.html"
|
||||
"./js"
|
||||
"./js/dummy.js"
|
||||
"./js/subdir"
|
||||
"./js/subdir/subdummy.js"
|
||||
"./js/subdir/test.js"]
|
||||
(sort (map :path
|
||||
(sut/get-resources-recursive
|
||||
"" "templates/themes/bootstrap4-test" ["."]))))))
|
||||
|
||||
(deftest test-delete-resource-recursive
|
||||
(deftest test-get-distinct-markup-dirs
|
||||
(is (=
|
||||
["test_pages"
|
||||
"test_pages/home"
|
||||
"test_posts"
|
||||
"test_posts/home"]
|
||||
(sort (map :path
|
||||
(sut/get-distinct-markup-dirs
|
||||
"not-existing-get-from-cp"
|
||||
"test_posts" "test_pages"
|
||||
""))))))
|
||||
|
||||
(deftest test-distinct-resources-by-path
|
||||
(is (= [{:path "pages/test"}
|
||||
{:path "pages/test1"}
|
||||
{:path "pages/test2"}]
|
||||
(sut/distinct-resources-by-path [{:path "pages/test"}
|
||||
{:path "pages/test1"}
|
||||
{:path "pages/test2"}
|
||||
{:path "pages/test1"}]))))
|
||||
|
||||
(deftest test-create-dirs-from-markup-folders!
|
||||
(is (do
|
||||
(sut/delete-resource-recursive! (str target "2"))
|
||||
(sut/create-dirs-from-markup-folders!
|
||||
"not-existing-get-from-cp" "test_posts" "test_pages"
|
||||
(str target "2") "")
|
||||
(and (verify-dir-exists
|
||||
(str (str target "2") "/test_pages"))
|
||||
(verify-dir-exists
|
||||
(str (str target "2") "/test_posts"))
|
||||
(verify-dir-exists
|
||||
(str (str target "2") "/test_pages/home"))))))
|
||||
|
||||
(deftest test-delete-resource-recursive!
|
||||
(is
|
||||
(do
|
||||
(.mkdir (io/file (str "target/tmp" target)))
|
||||
(sut/delete-resource-recursive! (str "target/tmp" target))
|
||||
(not (verify-dir-exists (str "target/tmp" target))))))
|
||||
(.mkdir (io/file target))
|
||||
(sut/delete-resource-recursive! target)
|
||||
(not (verify-dir-exists target)))))
|
||||
|
||||
(deftest test-filter-for-ignore-patterns
|
||||
(is (=
|
||||
|
@ -132,18 +151,17 @@
|
|||
(sut/filter-for-ignore-patterns #".*\.ignore" ["file.js" "file.ignore"]))))
|
||||
|
||||
(deftest test-copy-resources-from-theme! (is (do
|
||||
(sut/delete-resource-recursive! (str "target/tmp" target))
|
||||
(sut/copy-resources-from-theme! "./" theme target "")
|
||||
(and (verify-dir-exists
|
||||
(str target "/js"))
|
||||
(verify-file-exists
|
||||
(str target "/js/dummy.js"))
|
||||
(verify-dir-exists
|
||||
(str target "/js/subdir"))
|
||||
(verify-file-exists
|
||||
(str target "/js/subdir/subdummy.js"))
|
||||
(verify-file-exists
|
||||
(str target "/css/dummy.css"))
|
||||
(verify-file-exists
|
||||
(str target "/404.html"))
|
||||
))))
|
||||
(sut/delete-resource-recursive! target)
|
||||
(sut/copy-resources-from-theme! "./" theme target "")
|
||||
(and (verify-dir-exists
|
||||
(str target "/js"))
|
||||
(verify-file-exists
|
||||
(str target "/js/dummy.js"))
|
||||
(verify-dir-exists
|
||||
(str target "/js/subdir"))
|
||||
(verify-file-exists
|
||||
(str target "/js/subdir/subdummy.js"))
|
||||
(verify-file-exists
|
||||
(str target "/css/dummy.css"))
|
||||
(verify-file-exists
|
||||
(str target "/404.html"))))))
|
||||
|
|
|
@ -55,21 +55,21 @@ and more content.
|
|||
(let [mu (markdown)]
|
||||
(testing "Finds no files"
|
||||
(is (empty? (check-for-posts mu))
|
||||
(is (empty? (check-for-pages mu))))
|
||||
(is (empty? (check-for-pages mu))))
|
||||
|
||||
(let [dir->file
|
||||
[[check-for-posts "resources/templates/md/posts" "post.md"]
|
||||
[check-for-posts "resources/templates/posts" "post.md"]
|
||||
[check-for-pages "resources/templates/md/pages" "page.md"]
|
||||
[check-for-pages "resources/templates/pages" "page.md"]]]
|
||||
(doseq [[check-fn dir file] dir->file]
|
||||
(testing (str "Finds files in " dir)
|
||||
(create-entry dir file)
|
||||
(let [entries (check-fn mu)]
|
||||
(is (= 1 (count entries)))
|
||||
(is (= (.getAbsolutePath (File. (str dir File/separator file)))
|
||||
(.getAbsolutePath (first entries)))))
|
||||
(reset-resources)))))))
|
||||
(let [dir->file
|
||||
[[check-for-posts "resources/templates/md/posts" "post.md"]
|
||||
[check-for-posts "resources/templates/posts" "post.md"]
|
||||
[check-for-pages "resources/templates/md/pages" "page.md"]
|
||||
[check-for-pages "resources/templates/pages" "page.md"]]]
|
||||
(doseq [[check-fn dir file] dir->file]
|
||||
(testing (str "Finds files in " dir)
|
||||
(create-entry dir file)
|
||||
(let [entries (check-fn mu)]
|
||||
(is (= 1 (count entries)))
|
||||
(is (= (.getAbsolutePath (File. (str dir File/separator file)))
|
||||
(.getAbsolutePath (first entries)))))
|
||||
(reset-resources)))))))
|
||||
|
||||
(defmacro with-markup [mu & body]
|
||||
`(do
|
||||
|
@ -92,9 +92,9 @@ and more content.
|
|||
(str "entry" (m/ext mu)))))
|
||||
(with-markup mu
|
||||
(copy-resources-from-markup-folders
|
||||
{:post-root posts-root
|
||||
:page-root pages-root
|
||||
:blog-prefix "/blog"}))
|
||||
{:post-root posts-root
|
||||
:page-root pages-root
|
||||
:blog-prefix "/blog"}))
|
||||
(doseq [dir dirs]
|
||||
(is (.isDirectory (File. (str "resources/public/blog/" dir))))))
|
||||
|
||||
|
@ -102,9 +102,9 @@ and more content.
|
|||
(reset-resources)
|
||||
(testing "No pages or posts nothing to copy"
|
||||
(copy-resources-from-markup-folders
|
||||
{:post-root "pages"
|
||||
:page-root "posts"
|
||||
:blog-prefix "/blog"})
|
||||
{:post-root "pages"
|
||||
:page-root "posts"
|
||||
:blog-prefix "/blog"})
|
||||
(is (not (.isDirectory (File. (str "resources/public/blog/pages")))))
|
||||
(is (not (.isDirectory (File. (str "resources/public/blog/posts"))))))
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
(ns cryogen-core.hierarchic-test
|
||||
(:require
|
||||
[clojure.test :refer :all]
|
||||
[cryogen-core.hierarchic :as sut]))
|
||||
[clojure.test :refer :all]
|
||||
[cryogen-core.hierarchic :as sut]))
|
||||
|
||||
(defn- page [uri page-index]
|
||||
{:uri uri
|
||||
|
@ -16,54 +16,48 @@
|
|||
|
||||
(deftest test-normalized-page-root-uri
|
||||
(testing
|
||||
(is (= "" (sut/normalized-page-root-uri "")))
|
||||
(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/")))
|
||||
))
|
||||
(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")))
|
||||
))
|
||||
(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)
|
||||
])
|
||||
(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)]
|
||||
)])
|
||||
"/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)
|
||||
(page "/pages/nav1/nav13.html" 3)
|
||||
(page "/pages/nav1/nav11/nav112.html" 2)
|
||||
(page "/pages/nav1/nav12.html" 2)
|
||||
(page "/pages/nav1/nav11/xnav111.html" 1)
|
||||
])
|
||||
(page "/pages/nav1/nav11/xnav111.html" 1)])
|
||||
|
||||
(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)]
|
||||
)])
|
||||
"/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)])])
|
||||
|
||||
(def pages-clean-2 [(page "/pages/1/" 0)
|
||||
(page "/pages/2/" 1)
|
||||
|
@ -71,8 +65,8 @@
|
|||
|
||||
(def expected-clean-2 [(page "/pages/1/" 0)
|
||||
(enhanced-page
|
||||
"/pages/2/" 1
|
||||
[(page "/pages/2/22/" 0)])])
|
||||
"/pages/2/" 1
|
||||
[(page "/pages/2/22/" 0)])])
|
||||
|
||||
(def pages-clean-3 [(page "/1/" 0)
|
||||
(page "/2/" 1)
|
||||
|
@ -80,25 +74,22 @@
|
|||
|
||||
(def expected-clean-3 [(page "/1/" 0)
|
||||
(enhanced-page
|
||||
"/2/" 1
|
||||
[(page "/2/22/" 0)])])
|
||||
"/2/" 1
|
||||
[(page "/2/22/" 0)])])
|
||||
|
||||
(deftest test-hierarchic-pages
|
||||
(testing
|
||||
"hierarchic expectations"
|
||||
(is (= expected-clean-1
|
||||
(sut/build-hierarchic-map "pages" pages-clean-1)))
|
||||
(is (= expected-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)))
|
||||
)
|
||||
)
|
||||
"hierarchic expectations"
|
||||
(is (= expected-clean-1
|
||||
(sut/build-hierarchic-map "pages" pages-clean-1)))
|
||||
(is (= expected-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))))
|
||||
))
|
||||
(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))))))
|
|
@ -27,9 +27,9 @@
|
|||
; Test that the make-toc-entry ignores invalid input
|
||||
(deftest test-make-toc-entry
|
||||
(is (nil?
|
||||
(make-toc-entry nil "Text")))
|
||||
(make-toc-entry nil "Text")))
|
||||
(is (nil?
|
||||
(make-toc-entry "anchor" nil)))
|
||||
(make-toc-entry "anchor" nil)))
|
||||
(is (= [:li [:a {:href "#anchor"} "Text"]]
|
||||
(make-toc-entry "anchor" "Text"))))
|
||||
|
||||
|
@ -45,20 +45,20 @@
|
|||
no-headers [:div [:p "This is not a header"]]
|
||||
|
||||
closing-header-larger-than-opening-1
|
||||
[:div [:h2 [:a {:name "starting_low"}]
|
||||
"Starting Low"]
|
||||
[:h1 [:a {:name "finishing_high"}]
|
||||
"Finishing High"]]
|
||||
[:div [:h2 [:a {:name "starting_low"}]
|
||||
"Starting Low"]
|
||||
[:h1 [:a {:name "finishing_high"}]
|
||||
"Finishing High"]]
|
||||
|
||||
closing-header-larger-than-opening-2
|
||||
[:div [:h2 [:a {:name "starting_low"}]
|
||||
"Starting Low"]
|
||||
[:h4 [:a {:name "jumping_in"}]
|
||||
"Jumping Right In"]
|
||||
[:h3 [:a {:name "pulling_back"}]
|
||||
"But then pull back"]
|
||||
[:h2 [:a {:name "to_the_top"}]
|
||||
"To the top"]]]
|
||||
[:div [:h2 [:a {:name "starting_low"}]
|
||||
"Starting Low"]
|
||||
[:h4 [:a {:name "jumping_in"}]
|
||||
"Jumping Right In"]
|
||||
[:h3 [:a {:name "pulling_back"}]
|
||||
"But then pull back"]
|
||||
[:h2 [:a {:name "to_the_top"}]
|
||||
"To the top"]]]
|
||||
(is (= [:ol.content (seq [[:li [:a {:href "#test"} "Test"]]])]
|
||||
(-> simplest-header
|
||||
(parse-to-headings)
|
||||
|
@ -90,7 +90,6 @@
|
|||
"but outer headers cannot be less indented "
|
||||
"than the original header."]))))
|
||||
|
||||
|
||||
(deftest test-generate-toc
|
||||
(let [htmlString "<div><h2><a name=\"test\"></a>Test</h2></div>"]
|
||||
(is (= "<ol class=\"content\"><li><a href=\"#test\">Test</a></li></ol>"
|
||||
|
|
Loading…
Reference in a new issue