Пример #1
0
        public void Process(string relativeMediaPath = null)
        {
            PostName = Id + (string.IsNullOrEmpty(Slug) ? null : $"---{Slug}");

            // Most Hugo themes work best if there's a title in the frontmatter
            // Tumblr doesn't always have a title for a post, so we try to create one from the post
            if (string.IsNullOrWhiteSpace(_title))
            {
                if (!string.IsNullOrWhiteSpace(Summary))
                {
                    _title = Summary.GetFirstTextPhrase();
                }
            }
            if (string.IsNullOrWhiteSpace(_title))
            {
                var m = (TextContent)Content.FirstOrDefault(n => n.GetType() == typeof(TextContent));
                if (m != null)
                {
                    _title = m.Text.GetFirstTextPhrase();
                }
            }

            if (string.IsNullOrWhiteSpace(_title))
            {
                _title = "...";
            }
            else
            {
                _title = _title.EscapeYAML();
            }


            // Process all the content blocks
            int count = 1;

            foreach (var content in Content)
            {
                _markdown += content.Process($"{Id}_{count++}", relativeMediaPath);
                _copyList.AddRange(content.CopyList);
            }

            // Process all the reblogged content blocks
            if (Trail.Count != 0)
            {
                foreach (var trail in Trail)
                {
                    foreach (var content in trail.Content)
                    {
                        _markdown += content.Process($"{Id}_{count++}", relativeMediaPath);
                        _copyList.AddRange(content.CopyList);
                    }
                    var rebloggedFrom = Trail.FirstOrDefault().Blog;
                    if (rebloggedFrom != null)
                    {
                        _markdown += $">Reblogged from [{rebloggedFrom.Name}]({rebloggedFrom.Url})";
                    }
                }
            }

            // Build the list of Hugo Frontmatter
            DateTime date = DateTime.Parse(Date, CultureInfo.InvariantCulture);

            _hugoFrontMatter.TryAdd("id", Id.ToString());
            _hugoFrontMatter.TryAdd("date", date.ToUniversalTime().ToString("o", CultureInfo.InvariantCulture));
            _hugoFrontMatter.TryAdd("categories", $"[\"{OriginalType}\"]");
            _hugoFrontMatter.TryAdd("draft", (State == "draft" || State == "private") ? "true" : "false");
            _hugoFrontMatter.TryAdd("title", $"\"{_title}\"");
            _hugoFrontMatter.TryAdd("reblog", Trail.Count != 0 ? "true" : "false");
            if (Tags.Count > 0)
            {
                var cleanTags = new List <string>();
                foreach (var t in Tags)
                {
                    string tag = $"\"{t}\"";
                    cleanTags.Add(tag);
                }
                _hugoFrontMatter.TryAdd("tags", $"[{string.Join(",", cleanTags)}]");
            }
        }