Skip to content

Commit 73a9062

Browse files
committed
Fix ->nav-path for notebooks served over http
1 parent c388836 commit 73a9062

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Changes can be:
88

99
## Unreleased
1010

11+
* 🐞 Fix navigation path and reload when serving notebook over http
12+
1113
* 🌟 Add compatibility with Babashka
1214

1315
Requires Babashka 1.12.204 or newer.

src/nextjournal/clerk/webserver.clj

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,11 @@
242242
(or (symbol? file-or-ns) (instance? clojure.lang.Namespace file-or-ns))
243243
(str "'" file-or-ns)
244244

245-
(string? file-or-ns)
246-
(paths/drop-extension (or (paths/path-in-cwd file-or-ns) file-or-ns))))
245+
(re-matches #"^http?s://.*" file-or-ns)
246+
(str "/" file-or-ns)
247247

248-
#_(->nav-path (str (fs/file (fs/cwd) "notebooks/rule_30.clj")))
249-
#_(->nav-path 'nextjournal.clerk.index)
250-
#_(->nav-path "notebooks/rule_30.clj")
251-
#_(->nav-path 'nextjournal.clerk.home)
248+
(and (string? file-or-ns))
249+
(paths/drop-extension (or (paths/path-in-cwd file-or-ns) file-or-ns))))
252250

253251
(defn find-first-existing-file [files]
254252
(first (filter fs/exists? files)))
@@ -323,10 +321,10 @@
323321
file-or-ns)
324322
(catch ^:sci/error Exception e
325323
(u/if-bb
326-
(binding [*out* *err*]
327-
(println
328-
(str/join "\n" (sci.core/format-stacktrace (sci.core/stacktrace e)))))
329-
nil)))
324+
(binding [*out* *err*]
325+
(println
326+
(str/join "\n" (sci.core/format-stacktrace (sci.core/stacktrace e)))))
327+
nil)))
330328
{:status 200
331329
:headers {"Content-Type" "text/html" "Cache-Control" "no-store"}
332330
:body (view/->html {:doc (view/doc->viewer @!doc)

test/nextjournal/clerk/webserver_test.clj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns nextjournal.clerk.webserver-test
2-
(:require [clojure.java.io :as io]
2+
(:require [babashka.fs :as fs]
3+
[clojure.java.io :as io]
34
[clojure.test :refer [deftest is testing]]
45
[nextjournal.clerk.eval :as eval]
56
[nextjournal.clerk.test-utils]
@@ -12,6 +13,15 @@
1213
(is (= 'nextjournal.clerk.tap (webserver/->file-or-ns "'nextjournal.clerk.tap")))
1314
(is (= "notebooks/rule_30.clj" (webserver/->file-or-ns "notebooks/rule_30.clj"))))
1415

16+
(deftest ->nav-path-test
17+
(is (= "notebooks/rule_30"
18+
(webserver/->nav-path (str (fs/file (fs/cwd) "notebooks/rule_30.clj")))
19+
(webserver/->nav-path "notebooks/rule_30.clj")))
20+
(is (= "'nextjournal.clerk.home"
21+
(webserver/->nav-path 'nextjournal.clerk.home)))
22+
(is (= "/https://github.com/raw/nextjournal/clerk-demo/main/notebooks/rule_30.clj"
23+
(webserver/->nav-path "https://github.com/raw/nextjournal/clerk-demo/main/notebooks/rule_30.clj"))))
24+
1525
(deftest serve-blob
1626
(utils/when-not-bb
1727
(testing "lazy loading of simple range"

0 commit comments

Comments
 (0)