コード例 #1
0
        private void ConvertToHtml(BlogPostModel blogPost)
        {
            string layout = File.ReadAllText(Path.Join(topLevelConfig.Config.LayoutsDir, blogPost.Layout + ".hbs"));

            string result = handlebarsConverter.Convert(layout, new Dictionary <string, object>
            {
                { "post", blogPost.ToDictionary(topLevelConfig.Config) }
            });

            foreach (string postCategory in blogPost.Categories)
            {
                string languagePrefix = Config.MultipleLanguages switch
                {
                    true => blogPost.Language,
                    false => ""
                };

                string outputDir = Path.Join(
                    Config.OutputDir, languagePrefix, Slugify(postCategory),
                    blogPost.Date.Year.ToString(), blogPost.Date.Month.ToString(), blogPost.Date.Day.ToString(),
                    Slugify(blogPost.Title)
                    );

                string outputPath = Path.Join(outputDir, "index.html");

                Directory.CreateDirectory(outputDir);
                File.WriteAllText(outputPath, result);
            }
        }
    }
コード例 #2
0
        /// <param name="language">The language being used, or `null` if running in non-multi-language mode.</param>
        /// <param name="category">The name of the category whose page is being generated.</param>
        /// <param name="categoryPosts">A list of the posts in this category.</param>
        /// <param name="targetPath">The path to the output `.html` file.</param>
        protected void WriteCategoryPage(string language, string category, List <BlogPostModel> categoryPosts, string targetPath)
        {
            string sourcePath = Path.Join(Config.LayoutsDir, "category_archive.hbs");

            var extraData = new Dictionary <string, object>
            {
                { "category_posts", categoryPosts.Select(p => p.ToDictionary(Config)) },
                { "category_name", category },
                { "language", language }
            };

            string source = File.ReadAllText(sourcePath);
            string result = handlebarsConverter.Convert(source, extraData);

            File.WriteAllText(targetPath, result);
        }