#445 using HtmlText in tajik ganjoor

This commit is contained in:
Hamid Reza Mohammadi 2024-07-21 17:14:42 +03:30
parent 2412d40633
commit 81f21acd3a
2 changed files with 2 additions and 114 deletions

View File

@ -24,40 +24,9 @@
<p><a href="@poet.FullUrl">@poet.Nickname</a></p>
}
}
@if (Model.IsPoetPage)
else
{
<p>
@Model.GanjoorPage.PoetOrCat.Poet.Description
</p>
}
@if (Model.IsCatPage && !string.IsNullOrEmpty(@Model.GanjoorPage.PoetOrCat.Cat.Description))
{
<p>
@Model.GanjoorPage.PoetOrCat.Cat.Description
</p>
}
@if (Model.IsPoetPage || Model.IsCatPage)
{
@foreach (var cat in Model.GanjoorPage.PoetOrCat.Cat.Children)
{
<p>
<a href="@cat.FullUrl">@cat.Title</a>
</p>
}
@foreach (var poem in Model.GanjoorPage.PoetOrCat.Cat.Poems)
{
<p>
<a href="@($"{Model.GanjoorPage.PoetOrCat.Cat.FullUrl}/{poem.UrlSlug}")">@poem.Title</a>
</p>
}
}
@if(Model.IsPoemPage)
{
@Html.Raw(Model.HtmlText)
@Html.Raw(Model.GanjoorPage.HtmlText)
}
</div>

View File

@ -25,7 +25,6 @@ namespace TajikGanjoor.Pages
public string PreviousUrl { get; set; }
public string PreviousTitle { get; set; }
public string BreadCrumpUrls { get; set; }
public string HtmlText { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (bool.Parse(Configuration["MaintenanceMode"] ?? false.ToString()))
@ -71,7 +70,6 @@ namespace TajikGanjoor.Pages
{
case GanjoorPageType.PoemPage:
GanjoorPage.PoetOrCat = GanjoorPage.Poem.Category;
HtmlText = PrepareHtmlText(new List<GanjoorVerseViewModel>(GanjoorPage.Poem.Verses));
PrepareNextPre();
IsPoemPage = true;
break;
@ -236,85 +234,6 @@ namespace TajikGanjoor.Pages
}
}
private string PrepareHtmlText(List<GanjoorVerseViewModel> verses)
{
string htmlText = "";
int coupletIndex = 0;
for (int vIndex = 0; vIndex < verses.Count; vIndex++)
{
GanjoorVerseViewModel v = verses[vIndex];
if (v.VersePosition == VersePosition.CenteredVerse1)
{
coupletIndex++;
if (((vIndex + 1) < verses.Count) && (verses[vIndex + 1].VersePosition == VersePosition.CenteredVerse2))
{
htmlText += $"<div class=\"b2\" id=\"bn{coupletIndex}\"><p>{v.Text}</p>{Environment.NewLine}";
}
else
{
htmlText += $"<div class=\"b2\" id=\"bn{coupletIndex}\"><p>{v.Text}</p></div>{Environment.NewLine}";
}
}
else
if (v.VersePosition == VersePosition.CenteredVerse2)
{
htmlText += $"<p>{v.Text}</p></div>{Environment.NewLine}";
}
else
if (v.VersePosition == VersePosition.Right)
{
coupletIndex++;
htmlText += $"<div class=\"b\" id=\"bn{coupletIndex}\"><div class=\"m1\"><p>{v.Text}</p></div>{Environment.NewLine}";
}
else
if (v.VersePosition == VersePosition.Left)
{
htmlText += $"<div class=\"m2\"><p>{v.Text}</p></div></div>{Environment.NewLine}";
}
else
if (v.VersePosition == VersePosition.Comment)
{
htmlText += $"<div class=\"c\"><p>{v.Text}</p></div>{Environment.NewLine}";
}
else
if (v.VersePosition == VersePosition.Paragraph || v.VersePosition == VersePosition.Single)
{
coupletIndex++;
string[] lines = v.Text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
string cssClass = v.VersePosition == VersePosition.Paragraph ? "n" : "l";
if (lines.Length != 0)
{
if (v.Text.Length / lines.Length < 150)
{
htmlText += $"<div class=\"{cssClass}\" id=\"bn{coupletIndex}\"><p>{v.Text.Replace("\r\n", " ")}</p></div>{Environment.NewLine}";
}
else
{
foreach (string line in lines)
htmlText += $"<div class=\"{cssClass}\" id=\"bn{coupletIndex}\"><p>{line}</p></div>{Environment.NewLine}";
}
}
else
{
if (string.IsNullOrEmpty(v.Text))
{
htmlText += $"<div class=\"{cssClass}\" id=\"bn{coupletIndex}\"><p>&nbsp;</p></div>{Environment.NewLine}";//empty line!
}
else
{
htmlText += $"<div class=\"{cssClass}\" id=\"bn{coupletIndex}\"><p>{v.Text}</p></div>{Environment.NewLine}";//not brave enough to ignore it!
}
}
}
}
return htmlText.Trim();
}
public string? LastError { get; set; }
public bool AggressiveCacheEnabled