Skip to content

Commit 7f228ff

Browse files
committed
Fix ->nav-path for notebooks served over http (#755)
1 parent c388836 commit 7f228ff

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
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: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,12 @@
242242
(or (symbol? file-or-ns) (instance? clojure.lang.Namespace file-or-ns))
243243
(str "'" file-or-ns)
244244

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

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)
252-
253251
(defn find-first-existing-file [files]
254252
(first (filter fs/exists? files)))
255253

@@ -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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
(is (= 'nextjournal.clerk.tap (webserver/->file-or-ns "'nextjournal.clerk.tap")))
1313
(is (= "notebooks/rule_30.clj" (webserver/->file-or-ns "notebooks/rule_30.clj"))))
1414

15+
(deftest ->nav-path-test
16+
(is (= "notebooks/rule_30"
17+
#_(webserver/->nav-path (str (fs/file (fs/cwd) "notebooks/rule_30.clj"))) ;; failing on windows
18+
(webserver/->nav-path "notebooks/rule_30.clj")))
19+
(is (= "'nextjournal.clerk.home"
20+
(webserver/->nav-path 'nextjournal.clerk.home)))
21+
(is (= "/https://raw.githubusercontent.com/nextjournal/clerk-demo/main/notebooks/rule_30.clj"
22+
(webserver/->nav-path "https://raw.githubusercontent.com/nextjournal/clerk-demo/main/notebooks/rule_30.clj"))))
23+
1524
(deftest serve-blob
1625
(utils/when-not-bb
1726
(testing "lazy loading of simple range"

0 commit comments

Comments
 (0)