public async Task <string> ParseHtmlAsync(string tenant, string html) { var doc = new HtmlDocument(); doc.LoadHtml(html); var nodes = doc.DocumentNode.SelectNodes("//include[@article-alias and @category-alias]"); if (nodes == null) { return(html); } foreach (var node in nodes) { string alias = node.Attributes["article-alias"].Value; string categoryAlias = node.Attributes["category-alias"].Value; var model = await ContentModel.GetContentAsync(tenant, categoryAlias, alias).ConfigureAwait(false); if (model != null) { string contents = model.Contents; var newNode = HtmlNode.CreateNode(contents); node.ParentNode.ReplaceChild(newNode, node); } } return(doc.DocumentNode.OuterHtml); }
public async Task <ActionResult> PostAsync(string categoryAlias, string alias) { var model = await ContentModel.GetContentAsync(this.Tenant, categoryAlias, alias, true).ConfigureAwait(true); if (model == null) { return(this.View(GetLayoutPath(this.Tenant) + "404.cshtml")); } string path = GetLayoutPath(this.Tenant); string theme = this.GetTheme(); string layout = ThemeConfiguration.GetBlogLayout(this.Tenant, theme).Or(ThemeConfiguration.GetLayout(this.Tenant, theme)); model.LayoutPath = path; model.Layout = layout; model.Contents = await ContentExtensions.ParseHtmlAsync(this.Tenant, model.Contents).ConfigureAwait(true); return(this.View(this.GetRazorView <AreaRegistration>("Frontend/Blog/Post.cshtml", this.Tenant), model)); }
private async Task <Content> GetContentsAsync(string categoryAlias, string alias, bool isPost = false, FormCollection form = null) { var model = await ContentModel.GetContentAsync(this.Tenant, categoryAlias, alias).ConfigureAwait(false); if (model == null) { return(null); } bool isHomepage = string.IsNullOrWhiteSpace(categoryAlias) && string.IsNullOrWhiteSpace(alias); string path = GetLayoutPath(this.Tenant); string layout = isHomepage ? this.GetHomepageLayout() : this.GetLayout(); model.LayoutPath = path; model.Layout = layout; return(model); }