Render images server side. Remove JS hack to get images to render.

This commit is contained in:
Robert Marshall 2020-04-05 12:16:51 +01:00
parent 5d67e92245
commit 3eca70a102
9 changed files with 107 additions and 35 deletions

View file

@ -2,6 +2,7 @@ using System;
using Markdig;
using Pek.Markdig.HighlightJs;
using Website.Extensions;
using Website.Markdig.Extensions;
using Website.Models;
namespace Website.ViewModels
@ -19,10 +20,11 @@ namespace Website.ViewModels
private static string FormatTimestamp(DateTime timestamp) => timestamp.ToString($@"dddd \t\h\e d{timestamp.GetDaySuffix()} \o\f MMMM yyyy");
private static MarkdownPipeline GetPipeline() => new MarkdownPipelineBuilder()
//.UseAdvancedExtensions()
.UseAutoLinks()
.UseSoftlineBreakAsHardlineBreak()
.UseHighlightJs()
//.UseAdvancedExtensions()
.UseAutoLinks()
.UseSoftlineBreakAsHardlineBreak()
.UseHighlightJs()
.UseBlogImageRenderer()
.Build();
public int Id { get; }

View file

@ -10,13 +10,18 @@
<PackageReference Include="BuildBundlerMinifier" Version="3.2.435" />
<PackageReference Include="dapper" Version="2.0.30" />
<PackageReference Include="dapper.contrib" Version="2.0.30" />
<PackageReference Include="markdig" Version="0.18.0" />
<PackageReference Include="markdig" Version="0.18.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.0" />
<PackageReference Include="mysqlconnector" Version="0.61.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Pek.Markdig.HighlightJs" Version="0.5.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Website.Markdig.Extensions\Website.Markdig.Extensions.csproj" />
</ItemGroup>
<Target Name="BuildCss" BeforeTargets="Build">
<Exec WorkingDirectory="$(ProjectDir)" Command="npm install" />
<Exec WorkingDirectory="$(ProjectDir)" Command="npx gulp compile_scss" />

View file

@ -2,8 +2,7 @@
{
"outputFileName": "wwwroot/js/javascript.min.js",
"inputFiles": [
"wwwroot/js/javascript.js",
"wwwroot/js/blog.js"
"wwwroot/js/javascript.js"
],
"minify": {
"enabled": true,

View file

@ -1,28 +0,0 @@
documentReady(() => {
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));
});