Skip to content

Commit

Permalink
Use relative links inside the static-app (#132)
Browse files Browse the repository at this point in the history
Also rewrite top-level links to point to "index.html".
This allows browsing Clerk output with a browser directly on the file
system, and serving from buckets at arbitrary top-level directories.

Drop now obsolete `:path-prefix` option to `build-static-app!`.
  • Loading branch information
leahneukirchen authored Apr 14, 2022
1 parent 5a57e76 commit 6d4b873
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resources/viewer-js-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7peuLnjNi6U1svno2nKhFxnyAmy
4WQQKmi9imN2FttDVoa5h3o7yEa5
5 changes: 2 additions & 3 deletions src/nextjournal/clerk.clj
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@
- `:paths` a vector of relative paths to notebooks to include in the build
- `:bundle?` builds a single page app versus a folder with an html page for each notebook (defaults to `true`)
- `:path-prefix` a prefix to urls
- `:out-path` a relative path to a folder to contain the static pages (defaults to `\"public/build\"`)
- `:git/sha`, `:git/url` when both present, each page displays a link to `(str url \"blob\" sha path-to-notebook)`"
[opts docs]
Expand Down Expand Up @@ -488,8 +487,8 @@
(report-fn {:stage :finished :state state :duration duration :total-duration (elapsed-ms start)})))

#_(build-static-app! {:paths (take 5 clerk-docs)})
#_(build-static-app! {:paths ["index.clj" "notebooks/rule_30.clj" "notebooks/markdown.md"] :bundle? true})
#_(build-static-app! {:paths ["index.clj" "notebooks/rule_30.clj" "notebooks/markdown.md"] :bundle? false :path-prefix "build/"})
#_(build-static-app! {:paths ["index.clj" "notebooks/rule_30.clj" "notebooks/viewer_api.md"] :bundle? true})
#_(build-static-app! {:paths ["index.clj" "notebooks/rule_30.clj" "notebooks/viewer_api.md"] :bundle? false})
#_(build-static-app! {:paths ["notebooks/viewers/**"]})

;; And, as is the culture of our people, a commend block containing
Expand Down
11 changes: 9 additions & 2 deletions src/nextjournal/clerk/static_app.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
[reitit.frontend.easy :as rfe]
[sci.core :as sci]))

(defn doc-url [{:keys [path->url path-prefix bundle?]} path]
(defn doc-url [{:keys [path->url current-path bundle?]} path]
(let [url (path->url path)]
(if bundle?
(str "#/" url)
(str "/" path-prefix url))))
(let [url (cond-> url
(and (= (.. js/document -location -protocol) "file:")
(or (nil? url)
(str/ends-with? url "/")))
(str "index.html"))
dir-depth (get (frequencies current-path) \/ 0)
relative-root (apply str (repeat dir-depth "../"))]
(str relative-root url)))))

(defn show [{:as view-data :git/keys [sha url] :keys [doc path url->path]}]
(let [header [:div.mb-8.text-xs.sans-serif.text-gray-400.not-prose
Expand Down

0 comments on commit 6d4b873

Please sign in to comment.