You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.7 KiB

  1. @if (Page.ShowPaging == true)
  2. {
  3. <div class="col-6 col-sm-6 col-lg-4 rtl pull-right">
  4. <h2>@Model.Title</h2>
  5. <p class="excerpt">@MarkupHelper.GetDescription(Model.Content, 235, "...")</p>
  6. <p><a class="btn btn-primary" href="@Model.Url" role="button">بیشتر بخوانید &raquo;</a></p>
  7. </div>
  8. }
  9. else
  10. {
  11. <article class="post rtl" data-id="@Model.ID" itemscope itemtype="http://schema.org/BlogPosting" itemprop="blogPost">
  12. <h1 itemprop="headline name">
  13. <a href="@Model.Url" itemprop="url">@Model.Title</a>
  14. </h1>
  15. <div>
  16. <a href="@Model.Url#comments">
  17. <em class="glyphicon glyphicon-comment"></em>
  18. @Model.CountApprovedComments(Context) نظر
  19. </a>
  20. <abbr title="@Model.PubDate.ToLocalTime()" itemprop="datePublished">@Model.PubDate.ToLocalTime().ToString("MMMM d. yyyy")</abbr>
  21. @Categories()
  22. </div>
  23. <div itemprop="articleBody">@Html.Raw(Model.Content)</div>
  24. @if (Blog.CurrentPost != null)
  25. {
  26. <section id="comments" aria-label="Comments">
  27. @if (Model.CountApprovedComments(Context) > 0)
  28. {
  29. <h2>نظرات</h2>
  30. }
  31. @foreach (Comment comment in Model.Comments)
  32. {
  33. if (comment.IsApproved || !Blog.ModerateComments || Context.User.Identity.IsAuthenticated)
  34. {
  35. @RenderPage("Comment.cshtml", comment)
  36. }
  37. }
  38. </section>
  39. if (Model.AreCommentsOpen(Context))
  40. {
  41. @RenderPage("~/views/CommentForm.cshtml")
  42. }
  43. }
  44. </article>
  45. @helper Categories()
  46. {
  47. if (Model.Categories.Length > 0)
  48. {
  49. <ul class="categories rtl">
  50. <li><em class="glyphicon glyphicon-bookmark"></em> ارسال شده در: </li>
  51. @foreach (string cat in Model.Categories)
  52. {
  53. <li itemprop="articleSection">
  54. <a href="~/category/@HttpUtility.UrlEncode(cat.ToLowerInvariant())">@cat</a>
  55. </li>
  56. }
  57. </ul>
  58. }
  59. }
  60. }
  61. @functions{
  62. public class MarkupHelper
  63. {
  64. #region excerpt generation
  65. public static string GetDescription(string content, int length = 300, string ommission = "...")
  66. {
  67. return TruncateHtml(StripTags(content), 235, ommission);
  68. }
  69. public static string TruncateHtml(string input, int length = 300, string ommission = "...")
  70. {
  71. if (input == null || input.Length < length)
  72. return input;
  73. int nextSpace = input.LastIndexOf(" ", length);
  74. return string.Format("{0}" + ommission,
  75. input.Substring(0, (nextSpace > 0) ? nextSpace : length).Trim());
  76. }
  77. public static string StripTags(string markup)
  78. {
  79. try
  80. {
  81. StringReader stringReader = new StringReader(markup);
  82. System.Xml.XPath.XPathDocument xPathdocument;
  83. using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader,
  84. new System.Xml.XmlReaderSettings() { ConformanceLevel = System.Xml.ConformanceLevel.Fragment }))
  85. {
  86. xPathdocument = new System.Xml.XPath.XPathDocument(xmlReader);
  87. }
  88. return xPathdocument.CreateNavigator().Value;
  89. }
  90. catch
  91. {
  92. return string.Empty;
  93. }
  94. }
  95. #endregion
  96. }
  97. }