Skip to content

Commit

Permalink
Merge branch 'main' into remove-livejs-on-render
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude authored Nov 8, 2023
2 parents 7c81157 + 4a5557b commit dbab3bd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Instances of quickblog can be seen here:

- [#76](https://github.com/borkdude/quickblog/pull/76): Remove livejs script tag
on render. ([@jmglov](https://github.com/jmglov))
- [#75](https://github.com/borkdude/quickblog/pull/75): Omit preview posts from
index. ([@jmglov](https://github.com/jmglov))
- Support capitalization of tags
- [#66](https://github.com/borkdude/quickblog/issues/66): Unambigous ordering of posts, sorting by date (descending), post title, and then file name. ([@UnwarySage](https://github.com/UnwarySage))

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Instances of quickblog can be seen here:
- [Luc Engelen's blog](https://blog.cofx.nl/) - ([source](https://github.com/cofx22/blog))
- [Rattlin.blog](https://rattlin.blog/)
- [REP‘ti’L‘e’](https://kuna.us/)
- [Søren Sjørup's blog](https://zoren.dk)

Feel free to PR yours.

Expand Down
14 changes: 10 additions & 4 deletions src/quickblog/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@
out-dir]
:as opts}]
(let [index-posts #(->> (vals %)
lib/remove-previews
lib/sort-posts
(take num-index-posts))
posts (index-posts posts)
Expand Down Expand Up @@ -478,6 +479,10 @@
:ref "<filename>"
:require true}

:preview
{:desc "Create post as preview (won't be published to index, tags, or feeds)"
:default false}

:title
{:desc "Title of post"
:ref "<title>"
Expand All @@ -488,7 +493,7 @@
:ref "<tags>"
:coerce []}}}}
[opts]
(let [{:keys [file title posts-dir tags default-metadata]
(let [{:keys [file preview title posts-dir tags default-metadata]
:as opts} (apply-default-opts opts)
tags (cond (empty? tags) (:tags default-metadata)
(= tags [true]) [] ;; `--tags` without arguments
Expand All @@ -498,12 +503,13 @@
(let [file (if (re-matches #"^.+[.][^.]+$" file)
file
(str file ".md"))
post-file (fs/file posts-dir file)]
post-file (fs/file posts-dir file)
preview-str (if preview "Preview: true\n" "")]
(when-not (fs/exists? post-file)
(fs/create-dirs posts-dir)
(spit (fs/file posts-dir file)
(format "Title: %s\nDate: %s\nTags: %s\n\nWrite a blog post here!"
title (now) (str/join "," tags)))))))
(format "Title: %s\nDate: %s\nTags: %s\n%s\nWrite a blog post here!"
title (now) (str/join "," tags) preview-str))))))

(defn clean
"Removes cache and output directories"
Expand Down
9 changes: 9 additions & 0 deletions src/quickblog/internal.clj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@
:html
post-process-markdown)))

(defn remove-previews [posts]
(->> posts
(remove (fn [{:keys [file preview]}]
(let [preview? (Boolean/valueOf preview)]
(when preview?
(println "Skipping preview post:" file)
true))))))

(defn post-compare [a-post b-post]
;; Compare dates opposite the other values to force desending order
(compare [(:date b-post) (:title a-post) (:file a-post)]
Expand Down Expand Up @@ -337,6 +345,7 @@

(defn posts-by-tag [posts]
(->> (vals posts)
remove-previews
(sort-by :date)
(mapcat (fn [{:keys [tags] :as post}]
(map (fn [tag] [tag post]) tags)))
Expand Down
23 changes: 17 additions & 6 deletions test/quickblog/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@
(defn- write-test-post
([posts-dir]
(write-test-post posts-dir {}))
([posts-dir {:keys [file title date tags content]
([posts-dir {:keys [file title date tags content preview?]
:or {file "test.md"
title "Test post"
date "2022-01-02"
tags #{"clojure"}
content "Write a blog post here!"}}]
(write-test-file posts-dir file
(format "Title: %s\nDate: %s\nTags: %s\n\n%s"
title date (str/join "," tags) content))))
(let [preview-str (if preview? "Preview: true\n" "")]
(write-test-file posts-dir file
(format "Title: %s\nDate: %s\nTags: %s\n%s\n%s"
title date (str/join "," tags) preview-str content)))))

(deftest new-test
(with-dirs [posts-dir]
Expand Down Expand Up @@ -81,6 +82,10 @@
cache-dir
out-dir]
(write-test-post posts-dir {:tags #{"clojure" "tag with spaces"}})
(write-test-post posts-dir {:file "preview.md"
:title "This is a preview"
:tags #{"preview"}
:preview? true})
(write-test-file assets-dir "asset.txt" "something")
(api/render {:assets-dir assets-dir
:posts-dir posts-dir
Expand All @@ -91,7 +96,8 @@
(doseq [filename ["base.html" "post.html" "style.css"]]
(is (fs/exists? (fs/file templates-dir filename))))
(is (fs/exists? (fs/file cache-dir "test.md.pre-template.html")))
(doseq [filename ["test.html" "index.html" "archive.html"
(is (fs/exists? (fs/file cache-dir "preview.md.pre-template.html")))
(doseq [filename ["test.html" "preview.html" "index.html" "archive.html"
(fs/file "tags" "index.html")
(fs/file "tags" "clojure.html")
(fs/file "tags" "tag-with-spaces.html")
Expand All @@ -100,7 +106,12 @@
(is (str/includes? (slurp (fs/file out-dir "test.html"))
"<a href=\"tags/tag-with-spaces.html\">tag with spaces</a>"))
(is (str/includes? (slurp (fs/file out-dir "tags" "index.html"))
"<a href=\"tag-with-spaces.html\">tag with spaces</a>"))))
"<a href=\"tag-with-spaces.html\">tag with spaces</a>"))
;; Preview posts should be omitted from index, tags, and feeds
(is (not (fs/exists? (fs/file out-dir "tags" "preview.html"))))
(doseq [filename ["index.html" "atom.xml" "planetclojure.xml"]]
(is (not (str/includes? (slurp (fs/file out-dir filename))
"preview.html"))))))

(testing "with favicon"
(with-dirs [favicon-dir
Expand Down

0 comments on commit dbab3bd

Please sign in to comment.