-
-
Notifications
You must be signed in to change notification settings - Fork 694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make row available to render_cell
plugin hook
#1300
Comments
If I change the hookspec and add a row parameter, it works datasette/datasette/hookspecs.py Line 58 in 7a2ed9f
But to generate a URL, I need the primary keys, but I can't call |
If there's a simpler way to generate a URL for a specific row, I'm all ears |
render_cell
hookrender_cell
hook
I ended up using some JS as a workaround. First, add a JS file in extra_js_urls:
- '/static/app.js' then inside the script, find the blob download links and replace window.addEventListener('DOMContentLoaded', () => {
function renderBlobImages() {
document.querySelectorAll('a[href*=".blob"]').forEach(el => {
const img = document.createElement('img');
img.className = 'blob-image';
img.loading = 'lazy';
img.src = el.href.replace('.blob', '.jpg');
el.parentElement.replaceChild(img, el);
});
}
renderBlobImages();
}); while this does the job, I'd prefer handling this in Python where it belongs. |
Adding |
render_cell
hookrender_cell
plugin hook
Original title: Generating URL for a row inside
render_cell
hookHey,
I am using Datasette to view a database that contains video metadata. It has BLOB columns that contain video thumbnails in JPG format (around 100-500KB per row).
I've registered an output formatter that extends
datasette.blob_renderer.render_blob
function and serves the column withimage/jpeg
content type.This works well. I can visit
http://localhost:8001/mydb/videos/1.jpg?_blob_column=thumbnail
and view the image.I want to display the image directly with an
<img>
tag (lazy-loaded of course). So, I need a URL, because embedding base64 would increase the page size too much (each image > 100KB).Datasette generates a link with
.blob
extension for blob columns. It does this by callingdatasette.urls.row_blob
datasette/datasette/views/table.py
Lines 169 to 179 in 7a2ed9f
But I have no way of getting the row inside the
render_cell
hook.Any pointers?
The text was updated successfully, but these errors were encountered: