Skip to content

Commit

Permalink
Remove livejs script tag on render (borkdude#76)
Browse files Browse the repository at this point in the history
* Remove livejs script tag on render

* Update CHANGELOG

---------

Co-authored-by: Michiel Borkent <[email protected]>
  • Loading branch information
jmglov and borkdude authored Nov 8, 2023
1 parent 4a5557b commit fbfbd5a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Instances of quickblog can be seen here:

## Unreleased

- [#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
Expand Down
3 changes: 2 additions & 1 deletion src/quickblog/api.clj
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@
:as opts}
(-> opts
apply-default-opts
(assoc :watch "<script type=\"text/javascript\" src=\"https://livejs.com/live.js\"></script>")
(assoc :watch (format "<script type=\"text/javascript\" src=\"%s\"></script>"
lib/live-reload-script))
render)]
(reset! posts-cache (:posts opts))
(serve opts false)
Expand Down
8 changes: 7 additions & 1 deletion src/quickblog/internal.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
[markdown.core :as md]
[selmer.parser :as selmer]))

;; Script used for live reloading in watch mode
(def live-reload-script "https://livejs.com/live.js")

(def ^:private cache-filename "cache.edn")
(def ^:private resource-path "quickblog")
(def ^:private templates-resource-dir "templates")
Expand Down Expand Up @@ -281,7 +284,10 @@
post-file (fs/file posts-dir file)]
(or force-render
(rendering-modified? out-file
(cons post-file rendering-system-files))))))
(cons post-file rendering-system-files))
;; watch mode adds a live reloading script, which should be
;; removed on subsequent renders
(str/includes? (slurp out-file) live-reload-script)))))
(map first)
set))

Expand Down
23 changes: 21 additions & 2 deletions test/quickblog/api_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[clojure.string :as str]
[clojure.test :refer [deftest is testing use-fixtures]]
[babashka.fs :as fs]
[quickblog.api :as api])
[quickblog.api :as api]
[quickblog.internal :as lib])
(:import (java.util UUID)))

(def test-dir ".test")
Expand Down Expand Up @@ -208,7 +209,25 @@
:templates-dir templates-dir
:cache-dir cache-dir
:out-dir out-dir})
(is (str/includes? (slurp (fs/file out-dir "comments.html")) "<!-- a comment -->")))))
(is (str/includes? (slurp (fs/file out-dir "comments.html")) "<!-- a comment -->"))))

(testing "remove live reloading on render"
(with-dirs [posts-dir
templates-dir
cache-dir
out-dir]
(write-test-post posts-dir)
(api/render {:posts-dir posts-dir
:templates-dir templates-dir
:cache-dir cache-dir
:out-dir out-dir
:watch lib/live-reload-script})
(is (str/includes? (slurp (fs/file out-dir "test.html")) lib/live-reload-script))
(api/render {:posts-dir posts-dir
:templates-dir templates-dir
:cache-dir cache-dir
:out-dir out-dir})
(is (not (str/includes? (slurp (fs/file out-dir "test.html")) lib/live-reload-script))))))

;; disabled, flaky in CI, cc @jmglov
#_(deftest caching
Expand Down

0 comments on commit fbfbd5a

Please sign in to comment.