Esempio n. 1
0
        /// <summary>
        /// Entry-point. This is the first method that gets called by the .NET runtime.
        /// </summary>
        /// <param name="args">An array of command line arguments.</param>
        public static void Main(string[] args)
        {
            TopLevelConfig topLevelConfig = ReadConfig("config.yaml");
            var            program        = new Program(topLevelConfig);

            switch (args[0])
            {
            case "--build":
                DateTime start = DateTime.Now;

                program.ConvertPosts();
                program.ConvertPages();
                program.CopyStaticAssets();

                DateTime end = DateTime.Now;

                LogInfo($"Done rebuilding site in {(int) (end - start).TotalMilliseconds} ms");
                Console.WriteLine();

                break;

            case "--posts":
                program.ConvertPosts();
                break;

            case "--post":
                var blogPostConverter = new BlogPostConverter(topLevelConfig, program.handlebarsConverter);

                blogPostConverter.ProcessBlogPost(args[1]);
                break;

            default:
                if (args.Length == 2)
                {
                    string sourcePath = args[0];
                    string targetPath = args[1];

                    program.ConvertHandlebarsFile(sourcePath, targetPath);
                }
                else
                {
                    Console.WriteLine(
                        "Syntax: sitegen --build | --posts | --post <src-file> | <src-file> <target-file>");
                    Environment.Exit(1);
                }

                break;
            }
        }
Esempio n. 2
0
        private IEnumerable <BlogPostModel> ConvertPosts(IEnumerable <string> files)
        {
            var posts = new List <BlogPostModel>();

            var blogPostConverter = new BlogPostConverter(topLevelConfig, handlebarsConverter);

            foreach (string postSourceFile in files)
            {
                BlogPostModel blogPost = blogPostConverter.ProcessBlogPost(postSourceFile);
                LogInfo($"Converted {postSourceFile} to HTML");

                if (blogPost != null)
                {
                    posts.Add(blogPost);
                }
            }

            return(posts);
        }