Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into speedup-css-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Oct 18, 2023
2 parents 3073470 + 3fce7ea commit 383c2b7
Show file tree
Hide file tree
Showing 21 changed files with 345 additions and 108 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ Changes can be:

## Unreleased

...

## 0.15.957 (2023-09-28)

* 🔌 Offline support

Support working fully offline by adding a ServiceWorker to intercept and cache network requests to remote assets in the browser. It works for Clerk's js bundle, its tailwind css script, fonts and as well as javascript dynamically loaded using d3-require like Clerk's Vega and Plotly viewers.

To use it, you need to open Clerk in the browser when online to populate the cache. Viewers that are dynamically loaded (e.g. Vega or Plotly) need to be used once while offline to be cached. We're considering loading them on worker init in a follow up.

* 👁️ Improve viewer customization

* Simplify customization of number of rows displayed for table viewer using viewer-opts, e.g. `(clerk/table {::clerk/page-size 7})`. Pass `{::clerk/page-size nil}` to display elisions. Can also be passed a form metadata. Fixes [#406](https://github.com/nextjournal/clerk/issues/406).
Expand Down Expand Up @@ -47,6 +57,8 @@ Changes can be:

* 💫 Assign `:name` to every viewer in `default-viewers`

* 🐜 Ensure `var->location` returns a string path location fixing `Cannot open <#object[sun.nio.fs.UnixPath ,,,> as an InputStream` errors

* 🐞 Don't run existing files through `fs/glob`, fixes [#504](https://github.com/nextjournal/clerk/issues/504). Also improves performance of homepage.

* 🐞 Show correct non-var return value for deflike form, fixes [#499](https://github.com/nextjournal/clerk/issues/499)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ To use Clerk in your project, you'll need Java 11+ and [`clojure`](https://cloju
following dependency to your `deps.edn`:

```edn
{:deps {io.github.nextjournal/clerk {:mvn/version "0.14.919"}}}
{:deps {io.github.nextjournal/clerk {:mvn/version "0.15.957"}}}
```

Require and start Clerk as part of your system start, e.g. in `user.clj`:
Expand Down
2 changes: 1 addition & 1 deletion bb.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{:min-bb-version "0.9.159"
:paths ["bb"]
:deps {io.github.nextjournal/dejavu {:git/sha "4980e0cc18c9b09fb220874ace94ba6b57a749ca"}
io.github.nextjournal/cas-client {:git/sha "84ab35c3321c1e51a589fddbeee058aecd055bf8"}}
io.github.nextjournal/cas-client {:git/sha "22ef8360689cd3938e43a3223023ab1b9711818f"}}
:tasks
{:requires
([tasks :as t]
Expand Down
2 changes: 1 addition & 1 deletion book.clj
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ v/table-viewer
;; Also notably, there is a `:compile-css` option which compiles a css
;; file containing only the used CSS classes from the generated
;; markup. (Otherwise, Clerk is using Tailwind's Play CDN script which
;; can the page flicker, initially.)
;; can make the page flicker, initially.)

;; If set, the `:ssr` option will use React's server-side-rendering to
;; include the generated markup in the build HTML.
Expand Down
4 changes: 2 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
binaryage/devtools {:mvn/version "1.0.3"}
cider/cider-nrepl {:mvn/version "0.29.0"}
com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.0.3"}
io.github.nextjournal/cas-client {:git/sha "84ab35c3321c1e51a589fddbeee058aecd055bf8"}
io.github.nextjournal/cas-client {:git/sha "22ef8360689cd3938e43a3223023ab1b9711818f"}
org.slf4j/slf4j-nop {:mvn/version "2.0.7"}
org.babashka/cli {:mvn/version "0.5.40"}}
:extra-paths ["dev" "notebooks"]
Expand Down Expand Up @@ -74,7 +74,7 @@
io.github.nextjournal/clerk-slideshow {:git/sha "11a83fea564da04b9d17734f2031a4921d917893"}}}

:build {:deps {io.github.nextjournal/clerk {:local/root "."}
io.github.nextjournal/cas-client {:git/sha "84ab35c3321c1e51a589fddbeee058aecd055bf8"}
io.github.nextjournal/cas-client {:git/sha "22ef8360689cd3938e43a3223023ab1b9711818f"}
io.github.clojure/tools.build {:git/tag "v0.6.1" :git/sha "515b334"}
io.github.slipset/deps-deploy {:git/sha "b4359c5d67ca002d9ed0c4b41b710d7e5a82e3bf"}}
:extra-paths ["bb" "src" "resources"] ;; for loading lookup-url in build
Expand Down
83 changes: 0 additions & 83 deletions notebooks/doc.clj

This file was deleted.

2 changes: 1 addition & 1 deletion resources/META-INF/nextjournal/clerk/meta.edn
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{:version {:major 0, :minor 14, :rev-count 919}}
{:version {:major 0, :minor 15, :rev-count 957}}
54 changes: 54 additions & 0 deletions resources/public/clerk_service_worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const cacheName = 'clerk-browser-cache-v2';

const hosts = [
'https://fonts.bunny.net',
'https://cdn.skypack.dev',
'https://cdn.tailwindcss.com',
'https://storage.clerk.garden',
'https://cdn.jsdelivr.net',
'https://vega.github.io'
];

self.addEventListener('install', function(event) {
//console.log('install', event);
self.skipWaiting();
});

self.addEventListener('activate', function(event) {
//console.log('activate', event);

// Remove unwanted caches
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.map(function(cache) {
if (cache !== cacheName) {
console.log("Service Worker: Clearing old cache");
return caches.delete(cache);
}
}));
}));

return self.clients.claim()
});

self.addEventListener('fetch', function(event) {
//console.log(event);

event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request).then(function(response) {

hosts.map(function(host) {
if (event.request.url.indexOf(host) === 0) {
var clonedResponse = response.clone();
caches.open(cacheName).then(function(cache) {
cache.put(event.request, clonedResponse);
});
}
});
return response;
});
})
);
});
4 changes: 3 additions & 1 deletion src/nextjournal/clerk.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
Accepts ns using a quoted symbol or a `clojure.lang.Namespace`, calls `slurp` on all other arguments, e.g.:
```clj
(nextjournal.clerk/show! \"notebooks/vega.clj\")
(nextjournal.clerk/show! 'nextjournal.clerk.tap)
(nextjournal.clerk/show! (find-ns 'nextjournal.clerk.tap))
(nextjournal.clerk/show! \"https://raw.githubusercontent.com/nextjournal/clerk-demo/main/notebooks/rule_30.clj\")
(nextjournal.clerk/show! (java.io.StringReader. \";; # Notebook from String 👋\n(+ 41 1)\"))
```
"
([file-or-ns] (show! {} file-or-ns))
([opts file-or-ns]
Expand Down Expand Up @@ -63,7 +65,7 @@
{:keys [blob->result]} @webserver/!doc
{:keys [result time-ms]} (try (eval/time-ms (eval/+eval-results blob->result (assoc doc :set-status-fn webserver/set-status!)))
(catch Exception e
(throw (ex-info (str "`nextjournal.clerk/show!` encountered an eval error with: `" (pr-str file-or-ns) "`") {::doc doc} e))))]
(throw (ex-info (str "`nextjournal.clerk/show!` encountered an eval error with: `" (pr-str file-or-ns) "`") {::doc (assoc doc :blob->result blob->result)} e))))]
(println (str "Clerk evaluated '" file "' in " time-ms "ms."))
(webserver/update-doc! result))
(catch Exception e
Expand Down
7 changes: 4 additions & 3 deletions src/nextjournal/clerk/analyzer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -609,9 +609,10 @@
(let [digest-fn (case hash-type
:sha1 sha1-base58
:sha512 sha2-base58)]
(-> value
nippy/fast-freeze
digest-fn))))
(binding [nippy/*incl-metadata?* false]
(-> value
nippy/fast-freeze
digest-fn)))))

#_(valuehash (range 100))
#_(valuehash :sha1 (range 100))
Expand Down
Loading

0 comments on commit 383c2b7

Please sign in to comment.