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
|
||||
*******************************************************************************/
|
||||
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Cicm.Database.Models
|
||||
@@ -38,6 +39,9 @@ namespace Cicm.Database.Models
|
||||
public int CompanyId { get; set; }
|
||||
[MaxLength(262144, ErrorMessage = "Description is too long")]
|
||||
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; }
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Cicm.Database.Models;
|
||||
using Markdig;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
@@ -44,9 +45,11 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
public class CompanyDescriptionsController : Controller
|
||||
{
|
||||
readonly cicmContext _context;
|
||||
readonly MarkdownPipeline pipeline;
|
||||
|
||||
public CompanyDescriptionsController(cicmContext context)
|
||||
{
|
||||
pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
|
||||
_context = context;
|
||||
}
|
||||
|
||||
@@ -87,6 +90,7 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
{
|
||||
if(ModelState.IsValid)
|
||||
{
|
||||
companyDescription.Html = Markdown.ToHtml(companyDescription.Text, pipeline);
|
||||
_context.Add(companyDescription);
|
||||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction(nameof(Index));
|
||||
@@ -121,6 +125,7 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
companyDescription.Html = Markdown.ToHtml(companyDescription.Text, pipeline);
|
||||
_context.Update(companyDescription);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@
|
||||
@Html.DisplayFor(model => model.Company.Name)
|
||||
</dd>
|
||||
<dt class="col-sm-2">
|
||||
@Html.DisplayNameFor(model => model.Text)
|
||||
@Html.DisplayNameFor(model => model.Html)
|
||||
</dt>
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Text)
|
||||
@Html.Raw(Model.Html)
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
@@ -47,6 +47,12 @@
|
||||
<dd class="col-sm-10">
|
||||
@Html.DisplayFor(model => model.Company.Name)
|
||||
</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">
|
||||
@Html.DisplayNameFor(model => model.Text)
|
||||
</dt>
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace cicm_web.Controllers
|
||||
|
||||
if(company == null) return Index();
|
||||
|
||||
ViewBag.CompanyDescription = company.Description?.Text;
|
||||
ViewBag.CompanyDescription = company.Description?.Html ?? company.Description?.Text;
|
||||
|
||||
return View(company);
|
||||
}
|
||||
|
||||
@@ -29,9 +29,11 @@
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Cicm.Database;
|
||||
using Cicm.Database.Models;
|
||||
using DiscImageChef.Interop;
|
||||
using Markdig;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -140,12 +142,30 @@ namespace cicm_web
|
||||
end = DateTime.Now;
|
||||
Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m",
|
||||
(end - start).TotalSeconds);
|
||||
|
||||
start = DateTime.Now;
|
||||
Console.WriteLine("\u001b[31;1mImporting company logos...\u001b[0m");
|
||||
SvgRender.ImportCompanyLogos(context);
|
||||
end = DateTime.Now;
|
||||
Console.WriteLine("\u001b[31;1mTook \u001b[32;1m{0} seconds\u001b[31;1m...\u001b[0m",
|
||||
(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)
|
||||
{
|
||||
@@ -161,9 +181,7 @@ namespace cicm_web
|
||||
host.Run();
|
||||
}
|
||||
|
||||
static IWebHost BuildWebHost(string[] args)
|
||||
{
|
||||
return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().UseUrls("http://*:5000").Build();
|
||||
}
|
||||
static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().UseUrls("http://*:5000").Build();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<Version>3.0.99.424</Version>
|
||||
<Version>3.0.99.429</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
|
||||
Reference in New Issue
Block a user