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.

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