public BlogPost Build(PostData data) { var title = UrlSlug.Slugify(data.Title); var html = _markdownParser.ToTrustedHtml(data.Markdown); string?introHtml = null; var mainSectionIndex = data.Markdown.IndexOf("\n[//]: # (Main Section)", StringComparison.Ordinal); if (mainSectionIndex > -1) { var introMarkdown = data.Markdown.Substring(0, mainSectionIndex); introHtml = _markdownParser.ToTrustedHtml(introMarkdown); } var pageMetadata = _pageMetadataBuilder.Build(data.PageMetaData); var result = new BlogPost( data.FileName, data.Title, data.Author, data.PublishedOn, data.IsPublished, data.IsListed, title, html, introHtml, pageMetadata ); return(result); }
public async Task SendEmailAsync(string to, NotificationEvent @event) { var templateData = await _repository.GetEmailTemplateAsync(@event.EventName); if (templateData == null || !templateData.IsEnabled) { return; } var emailSubject = _templateEngine.Execute(templateData.Subject, @event.Parameters); string bodyHtml; switch (templateData.ContentsType) { case ContentsType.Markdown: var markdown = _templateEngine.Execute(templateData.Contents, @event.Parameters); bodyHtml = _markdownParser.ToTrustedHtml(markdown); break; case ContentsType.Html: bodyHtml = _templateEngine.Execute(templateData.Contents, @event.Parameters); break; default: throw new NotSupportedException($"Contents Type {templateData.ContentsType} is not supported for emails."); } string emailHtml; var layoutData = await _repository.GetLayoutHtmlAsync(); if (string.IsNullOrWhiteSpace(layoutData)) { emailHtml = bodyHtml; } else { var layoutParameters = new Dictionary <string, string>(@event.Parameters) { { "body", bodyHtml } }; emailHtml = _templateEngine.Execute(layoutData, layoutParameters); } var result = new ReadyEmail( @event.EventName, to, templateData.From, templateData.Cc, templateData.Bcc, emailSubject, emailHtml); await SendEmailSmtpAsync(result); }
public StaticPage Build(StaticPageData data) { var html = _markdownParser.ToTrustedHtml(data.Markdown); var pageMetadata = _pageMetadataBuilder.Build(data.PageMetaData); var result = new StaticPage( data.FileName, data.Title, data.UriSegment, data.IsPublished, html, pageMetadata); return(result); }