Ejemplo n.º 1
0
        internal static (MediaPost MediaPost, Guid Id) CreateMediaPost(String fileContents, MarkdownPipeline markdownPipeline)
        {
            var(frontMatter, content) = fileContents.SplitYamlFile();

            var deserializer = new DeserializerBuilder()
                               .WithNamingConvention(LowerCaseNamingConvention.Instance)
                               .Build();

            var yamlMediaPost = deserializer.Deserialize <YamlMediaPost>(frontMatter);

            Guid id        = yamlMediaPost.Id;
            var  mediaPost = new MediaPost()
            {
                Author      = yamlMediaPost.Author,
                Description = content.ToHtml(markdownPipeline),
                Media       = CreateMediaItem(yamlMediaPost.MediaType, yamlMediaPost.MediaItem),
                MediaType   = yamlMediaPost.MediaType,
                Posted      = yamlMediaPost.Posted,
                Tags        = yamlMediaPost.Tags,
                Title       = yamlMediaPost.Title,
                IsPublished = yamlMediaPost.IsPublished
            };

            return(mediaPost, id);
        }
Ejemplo n.º 2
0
        public IEnumerable <ContentItem> GetAllPosts()
        {
            var fileSystem = _serviceProvider.GetService <IFile>();
            var directory  = _serviceProvider.GetService <IDirectory>();

            var results  = new List <ContentItem>();
            var postPath = System.IO.Path.Combine(_rootPath, "posts");

            if (directory.Exists(postPath))
            {
                var files = directory.EnumerateFiles(postPath);
                foreach (var file in files.Where(f => f.ToUpperInvariant().EndsWith(".JSON", StringComparison.InvariantCulture)))
                {
                    var json        = fileSystem.ReadAllText(file);
                    var id          = Guid.Parse(System.IO.Path.GetFileNameWithoutExtension(file));
                    var mediaPost   = MediaPost.Create(json);
                    var contentItem = mediaPost.AsContentItem(id);
                    if (contentItem != null)
                    {
                        results.Add(contentItem);
                    }
                }
            }

            return(results);
        }
Ejemplo n.º 3
0
        internal static MediaPost Create(String json)
        {
            var result = Newtonsoft.Json.JsonConvert.DeserializeObject <MediaPost>(json);

            var post = Newtonsoft.Json.Linq.JObject.Parse(json);

            result.MediaItem = post[nameof(MediaPost.MediaItem)].Value <JObject>();
            result.Media     = MediaPost.CreateMediaItem(result.MediaType, result.MediaItem);

            return(result);
        }