Skip to content

Instantly share code, notes, and snippets.

@stefanJi
Created May 3, 2020 00:58
Show Gist options
  • Save stefanJi/ba956fa621055309ffd14c05d35e84b9 to your computer and use it in GitHub Desktop.
Save stefanJi/ba956fa621055309ffd14c05d35e84b9 to your computer and use it in GitHub Desktop.
hugo post image process. Resize, Center, FancyBox
let images = document.querySelectorAll('.article-entry img');
images.forEach(function (i) {
i.style.maxHeight = '450px'
i.style.maxWidth = '600px';
i.style.boxShadow = '2px 2px 8px 0px #888888';
i.style.borderRadius = '8px';
let a = document.createElement("a");
a.setAttribute("data-fancybox", "gallery");
a.setAttribute("href", i.getAttribute("src"));
a.setAttribute("data-caption", i.alt);
i.parentElement.appendChild(a);
let info = document.createElement("p");
info.style.fontSize = '12px';
info.style.color = "gray";
let tip = "click to see big pic";
if (i.alt != undefined && i.alt != '') {
tip = "[" + i.alt + "]" + tip;
}
info.innerText = tip;
i.parentElement.appendChild(info);
a.insertAdjacentElement("afterbegin", i);
i.parentElement.parentElement.style.textAlign = 'center';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment