예제 #1
0
        public object GetExtra(XElement element, dynamic currentModel)
        {
            _relativePathPrefix = GetRelativePathPrefix(element);
            _defaultLayoutFile  = GetDefaultLayoutFile(element);
            _shouldGenerateRss  = GetShouldGenerateRss(element);
            _shouldGenerateFolderForEachPost = GetShouldGenerateFolderForEachPost(element);
            _readmeName   = GetReadmeName(element);
            _isRootFolder = GetIsRootFolder(element);

            var childPagesFolder = GetChildPagesFolder(element);

            var childPagesOutputFolder = element.LastNode != null && element.LastNode.NodeType == XmlNodeType.Text
                ? element.LastNode.ToString().Trim().ToLowerInvariant()
                : "";
            var outputFolder     = Path.Combine(_configuration.OutputRootFolder, childPagesOutputFolder);
            var groupDefinitions = ParseGroupDefinitions(element);

            Directory.CreateDirectory(outputFolder);

            var files = Directory.GetFiles(childPagesFolder, "*.md", SearchOption.AllDirectories);

            var posts = files.Select(file => CreatePage(file, childPagesOutputFolder, childPagesFolder)).ToList();

            var pageGroups = CreateGroups(posts, groupDefinitions);

            currentModel.PageGroups = pageGroups;

            var indexPageFileName = GetIndexPageFileName(element);

            if (!string.IsNullOrWhiteSpace(indexPageFileName))
            {
                CreateChildPageIndex(posts, currentModel, outputFolder,
                                     Path.Combine(_configuration.TemplateRootFolder, element.Attribute("IndexLayoutFile").Value), indexPageFileName);
            }

            CreateTagPages(currentModel, outputFolder, childPagesOutputFolder,
                           Path.Combine(_configuration.TemplateRootFolder, element.Attribute("TagLayoutFile").Value),
                           Path.Combine(_configuration.TemplateRootFolder, element.Attribute("TagsIndexLayoutFile").Value));

            GeneratePages(posts, currentModel, _configuration.OutputRootFolder);

            CopyContent(childPagesFolder, outputFolder);
            CopyPostContent(posts, childPagesFolder, outputFolder);

            var result = new ChildPages
            {
                Name = childPagesOutputFolder, Pages = posts.OrderBy(x => x.Time).ToList(), Tags = _allTags.Select(x => x.Value).ToList()
            };

            if (_shouldGenerateRss)
            {
                GenerateRss(element, result, outputFolder);
            }

            return(result);
        }
예제 #2
0
        private void GenerateRss(XElement element, ChildPages result, string outputFolder)
        {
            var rssUri         = element.Attribute("RssUri").Value;
            var rssFeedName    = element.Attribute("RssFeedName").Value;
            var rssAuthor      = element.Attribute("RssAuthor").Value;
            var rssDescription = element.Attribute("RssDescription").Value;

            var feed = new SyndicationFeed(rssFeedName, rssDescription, new Uri(rssUri));

            feed.Authors.Add(new SyndicationPerson(rssAuthor));
            var feedItems = new List <SyndicationItem>();

            foreach (var page in result.Pages.Take(20))
            {
                var itemUri = rssUri + page.Location;
                var item    = new SyndicationItem(page.Title, page.Content, new Uri(itemUri));
                item.PublishDate = new DateTimeOffset(page.Time);
                item.Id          = page.Slurg;

                foreach (var tag in page.Tags)
                {
                    item.Categories.Add(new SyndicationCategory(tag.Name));
                }

                feedItems.Add(item);
            }

            feed.Items = feedItems;

            var settings = new XmlWriterSettings {
                Indent = true, IndentChars = "\t"
            };

            var feedLocation = Path.Combine(outputFolder, "rss.xml");

            using (var writer = XmlWriter.Create(feedLocation, settings))
            {
                feed.SaveAsRss20(writer);
            }

            result.Rss = result.Name + "/" + "rss.xml";
        }
예제 #3
0
        public object GetExtra(XElement element, dynamic currentModel)
        {
            relativePathPrefix = GetRelativePathPrefix(element);
            defaultLayoutFile  = GetDefaultLayoutFile(element);
            shouldGenerateRss  = GetShouldGenerateRss(element);
            var childPagesFolder = GetChildPagesFolder(element);

            var childPagesOutputFolder = element.Value.ToLowerInvariant();
            var outputFolder           = Path.Combine(configuration.OutputRootFolder, childPagesOutputFolder);

            Directory.CreateDirectory(outputFolder);

            var files = Directory.GetFiles(childPagesFolder, "*.md");

            var posts = files.Select(file => CreatePage(file, childPagesOutputFolder)).ToList();

            CreateChildPageIndex(posts, currentModel, outputFolder, Path.Combine(configuration.TemplateRootFolder, element.Attribute("IndexLayoutFile").Value));

            CreateTagPages(currentModel, outputFolder, childPagesOutputFolder, Path.Combine(configuration.TemplateRootFolder, element.Attribute("TagLayoutFile").Value), Path.Combine(configuration.TemplateRootFolder, element.Attribute("TagsIndexLayoutFile").Value));

            GeneratePages(posts.OrderBy(x => x.Time).ToList(), currentModel, outputFolder);

            CopyContent(childPagesFolder, outputFolder);

            var result = new ChildPages
            {
                Name  = childPagesOutputFolder,
                Pages = posts.OrderBy(x => x.Time).ToList(),
                Tags  = allTags.Select(x => x.Value).ToList(),
            };

            if (shouldGenerateRss)
            {
                GenerateRss(element, result, outputFolder);
            }

            return(result);
        }
예제 #4
0
        public object GetExtra(XElement element, dynamic currentModel)
        {
            relativePathPrefix = GetRelativePathPrefix(element);
            defaultLayoutFile = GetDefaultLayoutFile(element);
            shouldGenerateRss = GetShouldGenerateRss(element);
            var childPagesFolder = GetChildPagesFolder(element);

            var childPagesOutputFolder = element.Value.ToLowerInvariant();
            var outputFolder = Path.Combine(configuration.OutputRootFolder, childPagesOutputFolder);

            Directory.CreateDirectory(outputFolder);

            var files = Directory.GetFiles(childPagesFolder, "*.md");

            var posts = files.Select(file => CreatePage(file, childPagesOutputFolder)).ToList();

            CreateChildPageIndex(posts, currentModel, outputFolder, Path.Combine(configuration.TemplateRootFolder, element.Attribute("IndexLayoutFile").Value));

            CreateTagPages(currentModel, outputFolder, childPagesOutputFolder, Path.Combine(configuration.TemplateRootFolder, element.Attribute("TagLayoutFile").Value), Path.Combine(configuration.TemplateRootFolder, element.Attribute("TagsIndexLayoutFile").Value));

            GeneratePages(posts.OrderBy(x => x.Time).ToList(), currentModel, outputFolder);

            CopyContent(childPagesFolder, outputFolder);

            var result = new ChildPages
                             {
                                 Name = childPagesOutputFolder,
                                 Pages = posts.OrderBy(x => x.Time).ToList(),
                                 Tags = allTags.Select(x => x.Value).ToList(),

                             };

            if (shouldGenerateRss)
                GenerateRss(element, result, outputFolder);

            return result;
        }
예제 #5
0
        private void GenerateRss(XElement element, ChildPages result, string outputFolder)
        {
            var rssUri = element.Attribute("RssUri").Value;
            var rssFeedName = element.Attribute("RssFeedName").Value;
            var rssAuthor = element.Attribute("RssAuthor").Value;
            var rssDescription = element.Attribute("RssDescription").Value;

            var feed = new SyndicationFeed(rssFeedName, rssDescription, new Uri(rssUri));
            feed.Authors.Add(new SyndicationPerson(rssAuthor));
            var feedItems = new List<SyndicationItem>();

            foreach (var page in result.Pages.Take(20))
            {
                var itemUri = rssUri + page.Location;
                var item = new SyndicationItem(page.Title, page.Content, new Uri(itemUri));
                item.PublishDate = new DateTimeOffset(page.Time);
                item.Id = page.Slurg;

                foreach (var tag in page.Tags)
                {
                    item.Categories.Add(new SyndicationCategory(tag.Name));
                }

                feedItems.Add(item);
            }

            feed.Items = feedItems;

            var settings = new XmlWriterSettings { Indent = true, IndentChars = "\t" };

            var feedLocation = Path.Combine(outputFolder, "rss.xml");
            using (var writer = XmlWriter.Create(feedLocation, settings))
            {
                feed.SaveAsRss20(writer);
            }

            result.Rss = result.Name + "/" + "rss.xml";
        }