コード例 #1
0
ファイル: ChildPagesExtra.cs プロジェクト: huoxudong125/graze
        private Page CreatePage(string file, string childPagesRootFolder)
        {
            var fileContent = File.ReadAllText(file);
            var postContent = Regex.Split(fileContent, "---");
            var metadata = postContent[1];
            var content = postContent[2];

            var meta = metadata.GetTags();

            var title = meta["title"];
            var permalink = meta["permalink"];
            var description = meta["description"];
            var tags = meta["tags"].Split(',').Select(tag => tag.Trim()).ToList();

            var layout = meta.ContainsKey("layout") ? meta["layout"] : defaultLayoutFile;

            if (string.IsNullOrWhiteSpace(layout))
                throw new ArgumentNullException("Layout", "No layout set either in the post or in the configuration.");

            var layoutFile = Path.Combine(configuration.TemplateRootFolder, layout);
            DateTime time;
            if (!DateTime.TryParse(meta["time"], CultureInfo.InvariantCulture, DateTimeStyles.None, out time))
            {
                var parsingTimeFailedPage = string.Format("Parsing time failed. Page {0}, Date {1}", file, meta["time"]);
                throw new Exception(parsingTimeFailedPage);
            }

            var post = new Page
                           {
                               Description = description,
                               Location = Path.Combine(@"\", relativePathPrefix, childPagesRootFolder, permalink).Replace(@"\", @"/"),
                               Title = title,
                               Time = time,
                               TagNames = tags,
                               Slurg = permalink,
                               LayoutFile = layoutFile,
                               ParentPage = Path.Combine("/", relativePathPrefix, childPagesRootFolder)
                           };

            var options = new MarkdownOptions
            {
                AutoHyperlink = true,
                AutoNewlines = true,
                EmptyElementSuffix = "/>",
                EncodeProblemUrlCharacters = false,
                LinkEmails = true,
                StrictBoldItalic = true
            };

            var parser = new Markdown(options);

            post.Content = parser.Transform(content.Trim());

            foreach (var tag in post.TagNames)
            {
                if (allTags.ContainsKey(tag))
                {
                    allTags[tag].Pages.Add(post);
                    continue;
                }

                var value = new Tag { Name = tag, Pages = new List<Page> { post } };
                allTags.Add(tag, value);
            }

            return post;
        }
コード例 #2
0
ファイル: ChildPagesExtra.cs プロジェクト: huoxudong125/graze
        private void GeneratePage(Page page, dynamic currentModel, string outputFolder)
        {
            var modelDictionary = (IDictionary<string, object>)currentModel;
            if (modelDictionary.ContainsKey("Page"))
                modelDictionary.Remove("Page");

            modelDictionary.Add("Page", page);

            var postFolder = Path.Combine(outputFolder, page.Slurg);
            Directory.CreateDirectory(postFolder);

            var layoutContent = File.ReadAllText(page.LayoutFile);
            var staticPage = generator.GenerateOutput(currentModel, layoutContent);

            var postFileLocation = Path.Combine(outputFolder, page.Slurg, "index.html");

            File.WriteAllText(postFileLocation, staticPage);

            modelDictionary.Remove("Page");
        }
コード例 #3
0
        private Page CreatePage(string file, string childPagesRootFolder)
        {
            var fileContent = File.ReadAllText(file);
            var postContent = Regex.Split(fileContent, "---");
            var metadata = postContent[1];
            var content = postContent[2];

            var title = metadata.GetTagsValue("title");
            var permalink = metadata.GetTagsValue("permalink");
            var description = metadata.GetTagsValue("description");
            var tags = metadata.GetTagsValue("tags").Split(',').Select(tag => tag.Trim()).ToList();
            var layout = metadata.GetTagsValue("layout");
            var layoutFile = Path.Combine(configuration.TemplateRootFolder, layout);
            var time = DateTime.Parse(metadata.GetTagsValue("time"), CultureInfo.InvariantCulture);

            var post = new Page
                           {
                               Description = description,
                               Location = Path.Combine(@"\", relativePathPrefix, childPagesRootFolder, permalink).Replace(@"\", @"/"),
                               Title = title,
                               Time = time,
                               TagNames =  tags,
                               Slurg = permalink,
                               LayoutFile = layoutFile,
                           };

            var options = new MarkdownOptions
            {
                AutoHyperlink = true,
                AutoNewlines = true,
                EmptyElementSuffix = "/>",
                EncodeProblemUrlCharacters = false,
                LinkEmails = true,
                StrictBoldItalic = true
            };

            var parser = new Markdown(options);

            post.Content = parser.Transform(content.Trim());

            foreach (var tag in post.TagNames)
            {
                if (allTags.ContainsKey(tag))
                {
                    allTags[tag].Pages.Add(post);
                    continue;
                }

                var value = new Tag { Name = tag, Pages = new List<Page> { post } };
                allTags.Add(tag, value);
            }

            return post;
        }