@if (Page.ShowPaging == true)
{
    <div class="col-6 col-sm-6 col-lg-4 rtl pull-right">
        <h2>@Model.Title</h2>
        <p class="excerpt">@MarkupHelper.GetDescription(Model.Content, 235, "...")</p>
        <p><a class="btn btn-primary" href="@Model.Url" role="button">بیشتر بخوانید &raquo;</a></p>
    </div>
}
else
{
    <article class="post rtl" data-id="@Model.ID" itemscope itemtype="http://schema.org/BlogPosting" itemprop="blogPost">        
        <h1 itemprop="headline name">
            <a href="@Model.Url" itemprop="url">@Model.Title</a>
        </h1>
        <div>            
            <a href="@Model.Url#comments">
                <em class="glyphicon glyphicon-comment"></em>
                @Model.CountApprovedComments(Context) نظر
            </a>
            <abbr title="@Model.PubDate.ToLocalTime()" itemprop="datePublished">@Model.PubDate.ToLocalTime().ToString("MMMM d. yyyy")</abbr>
            @Categories()
        </div>

        <div itemprop="articleBody">@Html.Raw(Model.Content)</div>
            @if (Blog.CurrentPost != null)
            {
                <section id="comments" aria-label="Comments">
                    @if (Model.CountApprovedComments(Context) > 0)
                    {
                        <h2>نظرات</h2>
                    }

                    @foreach (Comment comment in Model.Comments)
                    {
                        if (comment.IsApproved || !Blog.ModerateComments || Context.User.Identity.IsAuthenticated)
                        {
                            @RenderPage("Comment.cshtml", comment)
                        }
                    }
                </section>

                if (Model.AreCommentsOpen(Context))
                {
                    @RenderPage("~/views/CommentForm.cshtml")
                }
            }
    </article>

    @helper Categories()
{
    if (Model.Categories.Length > 0)
    {
        <ul class="categories rtl">
            <li><em class="glyphicon glyphicon-bookmark"></em> ارسال شده در: </li>
            @foreach (string cat in Model.Categories)
            {
                <li itemprop="articleSection">
                    <a href="~/category/@HttpUtility.UrlEncode(cat.ToLowerInvariant())">@cat</a>
                </li>
            }
        </ul>
    }
}
}

@functions{
    public class MarkupHelper
    {
        #region excerpt generation

        public static string GetDescription(string content, int length = 300, string ommission = "...")
        {
            return TruncateHtml(StripTags(content), 235, ommission);
        }

        public static string TruncateHtml(string input, int length = 300, string ommission = "...")
        {
            if (input == null || input.Length < length)
                return input;
            int nextSpace = input.LastIndexOf(" ", length);
            return string.Format("{0}" + ommission,
                                  input.Substring(0, (nextSpace > 0) ? nextSpace : length).Trim());
        }

        public static string StripTags(string markup)
        {
            try
            {
                StringReader stringReader = new StringReader(markup);
                System.Xml.XPath.XPathDocument xPathdocument;
                using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader,
                        new System.Xml.XmlReaderSettings() { ConformanceLevel = System.Xml.ConformanceLevel.Fragment }))
                {
                    xPathdocument = new System.Xml.XPath.XPathDocument(xmlReader);
                }

                return xPathdocument.CreateNavigator().Value;
            }
            catch
            {
                return string.Empty;
            }
        }

        #endregion
    }
}