private void ReplaceInlineImages(IEnumerable <KeyValuePair <string, Guid> > createAttachments) { var imageReplacer = new ImageReplacer(); foreach (KeyValuePair <string, Guid> pair in createAttachments) { imageReplacer.Add(pair.Key, pair.Value); } if (imageReplacer.Count > 0) { _message.Body = imageReplacer.Replace(_message.Body); UpdateMessage(); } }
private void WritePosts(RSS content, ConverterOptions options) { var posts = content.Channel.Items.Where(item => item.PostType == "post" || item.PostType == "page").ToList(); _logger.LogInformation($"Found {posts.Count} posts/pages."); var attachments = content.Channel.Items.Where(item => item.PostType == "attachment").ToDictionary(key => key.PostId); var hugoPosts = posts.Select(post => _mapper.Map <Post>(post, opts => { opts.Items[ConverterLibraryAutoMapperProfile.ItemNameAttachments] = attachments; opts.Items[ConverterLibraryAutoMapperProfile.ItemNameSiteUrl] = content.Channel.Link; opts.Items[ConverterLibraryAutoMapperProfile.ItemNamePageResources] = options.PageResources; })); foreach (var hugoPost in hugoPosts) { string outputDirectory = hugoPost.Metadata.Type == "page" ? options.OutputDirectory : Path.Combine(options.OutputDirectory, HugoContentDirectoryName); string postFileName = Path.Combine(outputDirectory, hugoPost.Filename); string postFullDirectory = Path.GetDirectoryName(postFileName); Directory.CreateDirectory(postFullDirectory); string imageBaseUrl = options.PageResources ? null : GetImageBaseUrl(hugoPost, "/uploads"); var replacedImages = _imageReplacer.Replace(hugoPost, content.Channel.Link, imageBaseUrl, options.ImageShortCode); CopyReplacedImagesToOutputDirectory(options, replacedImages, postFullDirectory); var yaml = _yamlSerializer.Serialize(hugoPost.Metadata); StringBuilder hugoYaml = new StringBuilder(); hugoYaml.AppendLine("---"); hugoYaml.AppendLine(yaml); hugoYaml.AppendLine("---"); hugoYaml.AppendLine(hugoPost.Content); File.WriteAllText(postFileName, hugoYaml.ToString(), Encoding.UTF8); _logger.LogInformation($"Written '{postFileName}'."); } }