Пример #1
0
        public static SchemaToFileResult Run(FileSchemaEntity fileSchema)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(SPLIT_ROW);
            sb.AppendLine($"title: '{TextHelper.CleanBeforeMD(fileSchema.title)}'");
            sb.AppendLine($"description: '{TextHelper.CleanBeforeMD(fileSchema.description)}'");
            sb.AppendLine($"author: '{TextHelper.CleanBeforeMD(fileSchema.author)}'");
            sb.AppendLine($"date: {TextHelper.CleanBeforeMD(fileSchema.date)}");
            sb.AppendLine($"image: '{TextHelper.CleanBeforeMD(fileSchema.image)}'");
            sb.AppendLine($"draft: {fileSchema.draft}");
            sb.AppendLine($"slug: {TextHelper.CleanBeforeMD(fileSchema.slug)}");
            sb.AppendLine($"tags: [{fileSchema.tags}]");
            sb.AppendLine($"categories: [{fileSchema.categories}]");
            sb.AppendLine(SPLIT_ROW);
            sb.AppendLine($"{fileSchema.content}");
            sb.AppendLine("");

            DateTime date = DateTime.UtcNow.Date;

            _ = DateTime.TryParse(fileSchema.date, out date);

            SchemaToFileResult result = new SchemaToFileResult()
            {
                FileContent = sb.ToString(),
                FileName    = $"{fileSchema.FileName}",
                PostYYYY    = date.ToString("yyyy"),
                PostMM      = date.ToString("MM"),
                PostDD      = date.ToString("dd"),
            };

            return(result);
        }
Пример #2
0
        public static FileSchemaEntity Run(Post post)
        {
            FileSchemaEntity result = new FileSchemaEntity()
            {
                CategoriesList = new List <string>(),
                TagsList       = new List <string>(),
                title          = post.title,
                date           = post.pubDate,
                image          = post.seo_image,
                description    = post.seo_metadesc,
                draft          = false,
                FileName       = post.slug,
                seo_focuskw    = post.seo_focuskw,
                content        = post.content,
                author         = post.dcCreator,
                slug           = post.slug,
            };

            if (post.category != null && post.category.Count != 0)
            {
                result.CategoriesList = post.category.Select(x => x.name).OrderBy(x => x).ToList();
            }

            if (post.tags.TagArray != null && post.tags.TagArray.Count != 0)
            {
                result.TagsList = post.tags.TagArray.Select(x => x.name).OrderBy(x => x).ToList();
            }

            return(result);
        }