mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Store prerendered HTML from company description's markdown.
This commit is contained in:
1922
Cicm.Database/Migrations/20190518170817_AddPreRenderedCompanyDescription.Designer.cs
generated
Normal file
1922
Cicm.Database/Migrations/20190518170817_AddPreRenderedCompanyDescription.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace Cicm.Database.Migrations
|
||||||
|
{
|
||||||
|
public partial class AddPreRenderedCompanyDescription : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>("Html", "CompanyDescriptions", maxLength: 262144, nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn("Html", "CompanyDescriptions");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -28,6 +28,7 @@
|
|||||||
// Copyright © 2003-2018 Natalia Portillo
|
// Copyright © 2003-2018 Natalia Portillo
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Cicm.Database.Models
|
namespace Cicm.Database.Models
|
||||||
@@ -38,6 +39,9 @@ namespace Cicm.Database.Models
|
|||||||
public int CompanyId { get; set; }
|
public int CompanyId { get; set; }
|
||||||
[MaxLength(262144, ErrorMessage = "Description is too long")]
|
[MaxLength(262144, ErrorMessage = "Description is too long")]
|
||||||
public string Text { get; set; }
|
public string Text { get; set; }
|
||||||
|
[MaxLength(262144, ErrorMessage = "Description is too long")]
|
||||||
|
[DisplayName("HTML")]
|
||||||
|
public string Html { get; set; }
|
||||||
|
|
||||||
public virtual Company Company { get; set; }
|
public virtual Company Company { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Cicm.Database.Models;
|
using Cicm.Database.Models;
|
||||||
|
using Markdig;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
@@ -43,10 +44,12 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
[Authorize]
|
[Authorize]
|
||||||
public class CompanyDescriptionsController : Controller
|
public class CompanyDescriptionsController : Controller
|
||||||
{
|
{
|
||||||
readonly cicmContext _context;
|
readonly cicmContext _context;
|
||||||
|
readonly MarkdownPipeline pipeline;
|
||||||
|
|
||||||
public CompanyDescriptionsController(cicmContext context)
|
public CompanyDescriptionsController(cicmContext context)
|
||||||
{
|
{
|
||||||
|
pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
|
||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +90,7 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
{
|
{
|
||||||
if(ModelState.IsValid)
|
if(ModelState.IsValid)
|
||||||
{
|
{
|
||||||
|
companyDescription.Html = Markdown.ToHtml(companyDescription.Text, pipeline);
|
||||||
_context.Add(companyDescription);
|
_context.Add(companyDescription);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
@@ -121,6 +125,7 @@ namespace cicm_web.Areas.Admin.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
companyDescription.Html = Markdown.ToHtml(companyDescription.Text, pipeline);
|
||||||
_context.Update(companyDescription);
|
_context.Update(companyDescription);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,10 +49,10 @@
|
|||||||
@Html.DisplayFor(model => model.Company.Name)
|
@Html.DisplayFor(model => model.Company.Name)
|
||||||
</dd>
|
</dd>
|
||||||
<dt class="col-sm-2">
|
<dt class="col-sm-2">
|
||||||
@Html.DisplayNameFor(model => model.Text)
|
@Html.DisplayNameFor(model => model.Html)
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="col-sm-10">
|
<dd class="col-sm-10">
|
||||||
@Html.DisplayFor(model => model.Text)
|
@Html.Raw(Model.Html)
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,12 @@
|
|||||||
<dd class="col-sm-10">
|
<dd class="col-sm-10">
|
||||||
@Html.DisplayFor(model => model.Company.Name)
|
@Html.DisplayFor(model => model.Company.Name)
|
||||||
</dd>
|
</dd>
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Html)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.Raw(Model.Html)
|
||||||
|
</dd>
|
||||||
<dt class="col-sm-2">
|
<dt class="col-sm-2">
|
||||||
@Html.DisplayNameFor(model => model.Text)
|
@Html.DisplayNameFor(model => model.Text)
|
||||||
</dt>
|
</dt>
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace cicm_web.Controllers
|
|||||||
|
|
||||||
if(company == null) return Index();
|
if(company == null) return Index();
|
||||||
|
|
||||||
ViewBag.CompanyDescription = company.Description?.Text;
|
ViewBag.CompanyDescription = company.Description?.Html ?? company.Description?.Text;
|
||||||
|
|
||||||
return View(company);
|
return View(company);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,11 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using Cicm.Database;
|
using Cicm.Database;
|
||||||
using Cicm.Database.Models;
|
using Cicm.Database.Models;
|
||||||
using DiscImageChef.Interop;
|
using DiscImageChef.Interop;
|
||||||
|
using Markdig;
|
||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@@ -103,7 +105,7 @@ namespace cicm_web
|
|||||||
"DEBUG"
|
"DEBUG"
|
||||||
#else
|
#else
|
||||||
"RELEASE"
|
"RELEASE"
|
||||||
#endif
|
#endif
|
||||||
, DetectOS.GetPlatformName(DetectOS.GetRealPlatformID()),
|
, DetectOS.GetPlatformName(DetectOS.GetRealPlatformID()),
|
||||||
Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Is64BitProcess ? 64 : 32,
|
Environment.Is64BitOperatingSystem ? 64 : 32, Environment.Is64BitProcess ? 64 : 32,
|
||||||
DetectOS.IsMono ? "Mono" : ".NET Core",
|
DetectOS.IsMono ? "Mono" : ".NET Core",
|
||||||
@@ -140,12 +142,30 @@ namespace cicm_web
|
|||||||
end = DateTime.Now;
|
end = DateTime.Now;
|
||||||
Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m",
|
Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m",
|
||||||
(end - start).TotalSeconds);
|
(end - start).TotalSeconds);
|
||||||
|
|
||||||
start = DateTime.Now;
|
start = DateTime.Now;
|
||||||
Console.WriteLine("\u001b[31;1mImporting company logos...\u001b[0m");
|
Console.WriteLine("\u001b[31;1mImporting company logos...\u001b[0m");
|
||||||
SvgRender.ImportCompanyLogos(context);
|
SvgRender.ImportCompanyLogos(context);
|
||||||
end = DateTime.Now;
|
end = DateTime.Now;
|
||||||
Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m",
|
Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m",
|
||||||
(end - start).TotalSeconds);
|
(end - start).TotalSeconds);
|
||||||
|
|
||||||
|
start = DateTime.Now;
|
||||||
|
Console.WriteLine("\u001b[31;1mRendering markdown in company descriptions...\u001b[0m");
|
||||||
|
MarkdownPipeline pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
|
||||||
|
|
||||||
|
foreach(CompanyDescription companyDescription in
|
||||||
|
context.CompanyDescriptions.Where(cd => cd.Html == null))
|
||||||
|
{
|
||||||
|
companyDescription.Html = Markdown.ToHtml(companyDescription.Text, pipeline);
|
||||||
|
context.Update(companyDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
end = DateTime.Now;
|
||||||
|
Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m",
|
||||||
|
(end - start).TotalSeconds);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
@@ -161,9 +181,7 @@ namespace cicm_web
|
|||||||
host.Run();
|
host.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
static IWebHost BuildWebHost(string[] args)
|
static IWebHost BuildWebHost(string[] args) =>
|
||||||
{
|
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().UseUrls("http://*:5000").Build();
|
||||||
return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().UseUrls("http://*:5000").Build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
<Version>3.0.99.424</Version>
|
<Version>3.0.99.429</Version>
|
||||||
<Company>Canary Islands Computer Museum</Company>
|
<Company>Canary Islands Computer Museum</Company>
|
||||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||||
<Product>Canary Islands Computer Museum Website</Product>
|
<Product>Canary Islands Computer Museum Website</Product>
|
||||||
|
|||||||
Reference in New Issue
Block a user