From 44812c95d3773fe9c466839c677fd0580833c14f Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Sat, 20 Jul 2024 20:34:51 +0330 Subject: [PATCH] #445 display poems --- TajikGanjoor/Pages/Index.cshtml | 4 ++ TajikGanjoor/Pages/Index.cshtml.cs | 91 ++++++++++++++++++++++-- TajikGanjoor/Pages/Shared/_Layout.cshtml | 4 -- 3 files changed, 88 insertions(+), 11 deletions(-) diff --git a/TajikGanjoor/Pages/Index.cshtml b/TajikGanjoor/Pages/Index.cshtml index b12df70b..4257a7bc 100644 --- a/TajikGanjoor/Pages/Index.cshtml +++ b/TajikGanjoor/Pages/Index.cshtml @@ -53,7 +53,11 @@ @poem.TajikTitle

} + } + @if(Model.IsPoemPage) + { + @Html.Raw(Model.HtmlText) } diff --git a/TajikGanjoor/Pages/Index.cshtml.cs b/TajikGanjoor/Pages/Index.cshtml.cs index fb054505..2129ae28 100644 --- a/TajikGanjoor/Pages/Index.cshtml.cs +++ b/TajikGanjoor/Pages/Index.cshtml.cs @@ -25,8 +25,7 @@ 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 OnGetAsync() { if (bool.Parse(Configuration["MaintenanceMode"] ?? false.ToString())) @@ -72,14 +71,15 @@ namespace TajikGanjoor.Pages { case GanjoorPageType.PoemPage: GanjoorPage.PoetOrCat = GanjoorPage.Poem.Category; - _prepareNextPre(); + HtmlText = PrepareHtmlText(new List(GanjoorPage.Poem.Verses)); + PrepareNextPre(); IsPoemPage = true; break; case GanjoorPageType.PoetPage: IsPoetPage = true; break; case GanjoorPageType.CatPage: - _prepareNextPre(); + PrepareNextPre(); IsCatPage = true; break; } @@ -151,9 +151,7 @@ namespace TajikGanjoor.Pages Poets = poets ?? []; return true; } - - - private void _prepareNextPre() + private void PrepareNextPre() { if (GanjoorPage == null) return; switch (GanjoorPage.GanjoorPageType) @@ -218,6 +216,85 @@ namespace TajikGanjoor.Pages } } + private string PrepareHtmlText(List 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 += $"

{v.Tajik}

{Environment.NewLine}"; + } + else + { + htmlText += $"

{v.Tajik}

{Environment.NewLine}"; + + } + } + else + if (v.VersePosition == VersePosition.CenteredVerse2) + { + htmlText += $"

{v.Tajik}

{Environment.NewLine}"; + } + else + + if (v.VersePosition == VersePosition.Right) + { + coupletIndex++; + htmlText += $"

{v.Tajik}

{Environment.NewLine}"; + } + else + if (v.VersePosition == VersePosition.Left) + { + htmlText += $"

{v.Tajik}

{Environment.NewLine}"; + } + else + if (v.VersePosition == VersePosition.Comment) + { + htmlText += $"

{v.Tajik}

{Environment.NewLine}"; + } + else + if (v.VersePosition == VersePosition.Paragraph || v.VersePosition == VersePosition.Single) + { + coupletIndex++; + string[] lines = v.Tajik.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + + string cssClass = v.VersePosition == VersePosition.Paragraph ? "n" : "l"; + + if (lines.Length != 0) + { + if (v.Tajik.Length / lines.Length < 150) + { + htmlText += $"

{v.Tajik.Replace("\r\n", " ")}

{Environment.NewLine}"; + } + else + { + foreach (string line in lines) + htmlText += $"

{line}

{Environment.NewLine}"; + } + } + else + { + if (string.IsNullOrEmpty(v.Tajik)) + { + htmlText += $"

 

{Environment.NewLine}";//empty line! + } + else + { + htmlText += $"

{v.Tajik}

{Environment.NewLine}";//not brave enough to ignore it! + } + + } + } + } + return htmlText.Trim(); + } + public string? LastError { get; set; } public bool AggressiveCacheEnabled diff --git a/TajikGanjoor/Pages/Shared/_Layout.cshtml b/TajikGanjoor/Pages/Shared/_Layout.cshtml index dca3950d..833d9208 100644 --- a/TajikGanjoor/Pages/Shared/_Layout.cshtml +++ b/TajikGanjoor/Pages/Shared/_Layout.cshtml @@ -13,10 +13,6 @@