Comments (6)
Let us know when embedding files will be added natively.
from clerk.
It includes the image as base64 encoded inside the html, which has pros and cons.
This is currently only happening when generating a static html, when Clerk is running it's served via another request. We'll consider a knob in the future to allow publish images as files in the future.
from clerk.
This works right now but we want to make this easier, probably even include default viewers so this works out of the box.
;; # 🏞 Customizing Fetch
;; Showing how to use a custom `fetch-fn` with a `content-type` to let Clerk serve arbitrary things, in this case a PNG image.
(ns ^:nextjournal.clerk/no-cache image
(:require [nextjournal.clerk :as clerk]
[babashka.fs :as fs])
(:import (java.nio.file Path Files)))
;; We set a custom viewer for `java.nio.file.Path` that includes a `:fetch-fn`, returning a wrapped value with a `:nextjournal/content-type` key set.
(clerk/set-viewers! [{:pred #(instance? Path %)
:fetch-fn (fn [_ path] {:nextjournal/content-type "image/png"
:nextjournal/value (Files/readAllBytes path)})
:render-fn (fn [blob] (v/html [:img {:src (v/url-for blob)}]))}])
(fs/path "/Users/mk/dev/clerk-demo/datasets/james_clerk_maxwell.png")
from clerk.
I have tried this as well for dynamically generated images.
It is working as well for that case.
It includes the image as base64 encoded inside the html, which has pros and cons.
I am bit concerned on performance on this, but have not data so far
from clerk.
Thanks!
base64 encoding will blow the size of html for more than several images. base64 adds 25% of original size of the image.
Question about above example, what about support for more than one image type (say: png, jpg and gif)?
Also: does it work for relative paths and after building static pages? I want to push html to github and be sure that images still will be visible.
(haven't tried it yet)
from clerk.
Ok, look like it works well and images are embedded inside static html when building is done. Maybe consider copying files?
Multiple mime types can be recognized from a path and extension (and should be bundled to cover most popular file types).
Anyway it works well without too much hassle. Thanks a lot!
from clerk.
Related Issues (20)
- Confusing index behavior + cache invalidation with certain notebook links HOT 2
- Long footnotes can overlap code listings HOT 4
- Error in Windows file path
- Case where `clerk/row` displays only the first of its arguments HOT 4
- Environment setup: requiring cljc source files and possibility of using cljs HOT 3
- Katex renderer should not throw on error
- editor mode doesn't apply unquotes HOT 5
- clerk/vl doesn't update reactively HOT 1
- Having multiple tabs open with different URLs at the same time
- Using clerk as a standalone command line tool only displays default home.clj only HOT 3
- Page size option throws on string values
- A Notebook throwing Exceptions leads to a blank Screen
- Clerk in Babashka fails with "Unable to resolve classname: io.methvin.watcher.DirectoryChangeEvent" HOT 2
- Rendering of Images is broken in static Apps
- Tap Inspector re-renders tapped values
- Default index shows a misleading notice HOT 1
- Hidden viewer eval results produce vertical whitespace HOT 1
- Defs in clerk fragments are shown as vars
- Clerk Editor broke HOT 1
- Invalid LaTeX math appears to cause the Clerk browser UI to crash HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clerk.