Ejemplo n.º 1
0
        Post parsePost(FileInfo file)
        {
            using (var str = file.OpenRead())
            {
                var xml  = XDocument.Load(str);
                var head = xml.Root.Element("head");
                var body = xml.Root.Element("body");

                var title = (string)head.Element("title");
                var url   = (string)head.Elements("meta").Select(m => m.Attribute("url")).Single(u => u != null);
                var tags  = (string)head.Elements("meta").Select(m => m.Attribute("tags")).Single(u => u != null);

                //var post = new PostDetail(url, DateTime.Now, PostType.Article);
                var post = new Post();
                post.SID       = url;
                post.Date      = DateTime.Now;
                post.Partition = post.Date.Year.ToString();


                //string fragment = String.Concat(post.Partition, "/", post.ID, "/");
                //var storageUrl = _loader.GetFileURI(post.Year, post.Name, file )
                Func <string, string> getUrl = f => _loader.GetFileURI(post.Partition, post.SID, f).ToString();

                var postSummary = new XElement("div", body.Element("summary").Nodes()).FixLinks(getUrl).ToString();
                var postBody    = new XElement("div", body.Element("article").Nodes()).FixLinks(getUrl).ToString();

                post.Title   = title;
                post.Summary = postSummary;
                post.Body    = postBody;
                post.Active  = true;
                //post.Tags = tags;

                return(post);
            }
        }