Updating to allow mp3

This commit is contained in:
2026-03-08 17:38:16 +00:00
parent 8bd8c53cb5
commit d560cf66dc
5 changed files with 125 additions and 21 deletions

View File

@@ -11,3 +11,5 @@
- [[id:65F747B1-3CB2-429A-9E26-ED8BC169E689][Recipes MOC]] - [[id:65F747B1-3CB2-429A-9E26-ED8BC169E689][Recipes MOC]]
- [[id:45eefd5b-a3d8-4b83-84ea-5a6984025755][Proverbs]] - [[id:45eefd5b-a3d8-4b83-84ea-5a6984025755][Proverbs]]

View File

@@ -6,6 +6,13 @@ document.addEventListener('DOMContentLoaded', () => {
function setupGalleries(root = document) { function setupGalleries(root = document) {
const imgs = root.querySelectorAll('.figure img, img.org-svg'); const imgs = root.querySelectorAll('.figure img, img.org-svg');
const VIDEO_EXTENSIONS = ['mp4','webm','mov','m4v','ogv'];
function isVideo(href){
if(!href) return false;
href = href.toLowerCase();
return VIDEO_EXTENSIONS.some(ext => href.endsWith('.' + ext));
}
imgs.forEach((img) => { imgs.forEach((img) => {
if (img.closest('a')) return; if (img.closest('a')) return;
@@ -19,7 +26,9 @@ document.addEventListener('DOMContentLoaded', () => {
a.dataset.width = img.naturalWidth || img.width || 1920; a.dataset.width = img.naturalWidth || img.width || 1920;
a.dataset.height = img.naturalHeight || img.height || 1080; a.dataset.height = img.naturalHeight || img.height || 1080;
}; };
if (img.complete) setDims(); else img.addEventListener('load', setDims);
if (img.complete) setDims();
else img.addEventListener('load', setDims);
img.style.cursor = 'zoom-in'; img.style.cursor = 'zoom-in';
img.parentElement.insertBefore(a, img); img.parentElement.insertBefore(a, img);
@@ -27,8 +36,12 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
const containers = root.querySelectorAll('main, article, .content, body'); const containers = root.querySelectorAll('main, article, .content, body');
containers.forEach((container) => { containers.forEach((container) => {
const links = Array.from(container.querySelectorAll('.figure a, a:has(img.org-svg)')); //const links = Array.from(container.querySelectorAll('.figure a, a:has(img.org-svg)'));
const links = Array.from(container.querySelectorAll(
'.figure a, a:has(img.org-svg), a[href$=".mp4"], a[href$=".webm"], a[href$=".mov"], a[href$=".m4v"], a[href$=".ogv"]'
));
if (!links.length) return; if (!links.length) return;
links.forEach((link) => { links.forEach((link) => {
@@ -37,27 +50,93 @@ document.addEventListener('DOMContentLoaded', () => {
link.addEventListener('click', (e) => { link.addEventListener('click', (e) => {
e.preventDefault(); e.preventDefault();
document.querySelectorAll(".theme-toggle").forEach(el => el.classList.add("hidden"));
bp.open({ bp.open({
items: links, items: links,
el: link, el: link,
caption: (el) => el.querySelector('img')?.alt || el.title || '', caption: (el) => el.querySelector('img')?.alt || el.title || '',
maxZoom: 40, maxZoom: 40,
onClose(containerEl) { onOpen(containerEl){
destroyPanZoom(); const linkEl = bp.currItem;
const href = linkEl?.href || "";
if (isVideo(href)) {
teardownRotation(); teardownRotation();
if (containerEl) containerEl.classList.add('bp-fadeout');
document.querySelectorAll(".theme-toggle").forEach(el => el.classList.remove("hidden")); const htmlLayer = containerEl.querySelector(".bp-html");
}, const imgLayer = containerEl.querySelector(".bp-img");
onOpen(containerEl) { setupRotation(containerEl); enhanceSVG(containerEl); },
onUpdate(containerEl){ setupRotation(containerEl); enhanceSVG(containerEl); } if (imgLayer) imgLayer.style.display = "none";
htmlLayer.innerHTML = `
<video controls autoplay style="max-width:95vw; max-height:95vh">
<source src="${href}" type="video/mp4">
</video>
`;
return;
}
setupRotation(containerEl);
enhanceSVG(containerEl);
}
}); });
}); });
}); });
}); });
} }
function setupVideo(root=document){
const links = root.querySelectorAll('a[href]');
links.forEach(link=>{
if(link.dataset.videoProcessed) return;
const href = link.getAttribute("href");
if(!isVideo(href)) return;
link.dataset.videoProcessed = "true";
const video = document.createElement("video");
video.controls = true;
video.preload = "metadata";
video.style.maxWidth = "100%";
video.style.borderRadius = "6px";
const source = document.createElement("source");
source.src = href;
source.type = "video/" + href.split('.').pop();
video.appendChild(source);
link.parentNode.replaceChild(video, link);
});
}
function setupAudio(root = document) {
const audioLinks = root.querySelectorAll('a[href$=".mp3"]');
audioLinks.forEach((link) => {
if (link.dataset.audioProcessed) return;
link.dataset.audioProcessed = "true";
const src = link.href;
const wrapper = document.createElement("div");
wrapper.className = "audio-player";
const audio = document.createElement("audio");
audio.controls = true;
audio.preload = "metadata";
audio.src = src;
const label = document.createElement("div");
label.className = "audio-label";
label.textContent = link.textContent || src.split("/").pop();
wrapper.appendChild(label);
wrapper.appendChild(audio);
link.replaceWith(wrapper);
});
}
const bp = BiggerPicture({ target: document.body }); const bp = BiggerPicture({ target: document.body });
let activeContainer = null; let activeContainer = null;
@@ -233,12 +312,17 @@ document.addEventListener('DOMContentLoaded', () => {
} }
setupGalleries(document); setupGalleries(document);
setupAudio(document);
const dynamicObserver = new MutationObserver((mutations) => { const dynamicObserver = new MutationObserver((mutations) => {
for (const m of mutations) { for (const m of mutations) {
for (const node of m.addedNodes) { for (const node of m.addedNodes) {
if (!(node instanceof HTMLElement)) continue; if (!(node instanceof HTMLElement)) continue;
if (node.querySelectorAll) setupGalleries(node); if (node.querySelectorAll){
setupGalleries(node);
setupAudio(node);
setupVideo(node);
}
} }
} }
}); });
@@ -251,6 +335,8 @@ document.addEventListener('DOMContentLoaded', () => {
lastUrl = currentUrl; lastUrl = currentUrl;
console.log('[gallery-init] URL changed → reinitializing galleries'); console.log('[gallery-init] URL changed → reinitializing galleries');
setupGalleries(document); setupGalleries(document);
setupAudio(document);
setupVideo(document);
} }
}); });
urlObserver.observe(document, { subtree: true, childList: true }); urlObserver.observe(document, { subtree: true, childList: true });

View File

@@ -1044,3 +1044,19 @@ body.pane-fullscreen #content.content { max-width: 860px; }
justify-content: flex-end; justify-content: flex-end;
} }
} }
.audio-player {
margin: 1rem 0;
padding: 0.6rem 0.8rem;
border-radius: 8px;
background: var(--bg-secondary);
}
.audio-label {
font-size: 0.85rem;
opacity: 0.7;
margin-bottom: 0.4rem;
}
.audio-player audio {
width: 100%;
}

View File

@@ -311,7 +311,7 @@ Created with %c on <a href=\"https://www.archlinux.org/\">Arch</a> <a href=\"htt
("org-static" ("org-static"
:base-directory "/home/zaine/master-folder/org_files/org_roam/assets/" :base-directory "/home/zaine/master-folder/org_files/org_roam/assets/"
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|svg" :base-extension "css\\|js\\|png\\|jpg\\|gif\\|svg\\|mp4\\|mp3"
:publishing-directory "/home/zaine/master-folder/org_files/org_roam/output/assets/" :publishing-directory "/home/zaine/master-folder/org_files/org_roam/output/assets/"
:recursive t :recursive t
:publishing-function org-publish-attachment))) :publishing-function org-publish-attachment)))

View File

@@ -9,5 +9,5 @@ Generating the JSON output...
Building project (full rebuild with search index)... Building project (full rebuild with search index)...
emacs -Q --script lisp/build.el emacs -Q --script lisp/build.el
Loading /home/zaine/master-folder/org_files/org_roam/lisp/macros.el (source)... Loading /home/zaine/master-folder/org_files/org_roam/lisp/macros.el (source)...
Starting full rebuild at 2026-03-08 16:13:33 Starting full rebuild at 2026-03-08 17:33:18
✅ Full rebuild complete in 6.72 seconds ✅ Full rebuild complete in 6.07 seconds