Sort out blog images

This commit is contained in:
Robert Marshall 2020-01-04 12:33:18 +00:00
parent e77298ae54
commit b68f7736c8
2 changed files with 147 additions and 111 deletions

View file

@ -4,6 +4,38 @@
ViewData["Title"] = Model.Title;
}
@Html.Raw(Model.ContentHtml)
<article class="blog-post">
@Html.Raw(Model.ContentHtml)
</article>
<small>Posted on @Model.Timestamp</small>
<small>Posted on @Model.Timestamp</small>
<script type="text/javascript">
function adornImage(image, append) {
var parent = image.parentNode;
parent.removeChild(image);
image.className = "blog-post__image-container--image";
var tagLine = document.createElement("span");
tagLine.className = "blog-post__image-container--tagline";
tagLine.innerText = image.getAttribute("alt");
var container = document.createElement("div");
container.className = "blog-post__image-container";
container.appendChild(image);
container.appendChild(tagLine);
var containerContainer = document.createElement("div");
containerContainer.className = "blog-post__image-container--container";
containerContainer.appendChild(container);
if (append)
parent.appendChild(containerContainer);
else
parent.prepend(containerContainer);
}
document.querySelectorAll("p>img:only-child,p>img:first-child").forEach(image => adornImage(image, false));
document.querySelectorAll("p>img:last-child").forEach(image => adornImage(image, true));
</script>