Beispiel #1
0
        /// <summary>
        /// Creates a site project from disk.
        /// </summary>
        /// <param name="path">The path to the configuration file.</param>
        /// <returns>The project.</returns>
        public static SiteProject FromDisk(DirectoryInfo path, string language = null)
        {
            if (!path.Exists)
            {
                throw new FileNotFoundException("Unable to load the project, as the directory specified does not exist. Directory: " + path.FullName);
            }

            // Prepare a project
            var project = new SiteProject();

            // Set the path where the project lives
            project.Directory     = path;
            project.Configuration = SiteConfig.Read(path);

            // If we don't have the language specified, find the first language
            // in the configuration file.
            if (language == null && project.Configuration.Languages != null)
            {
                language = project.Configuration.Languages.FirstOrDefault();
            }
            if (language == null)
            {
                language = "default";
            }

            // Set the destination to the sub-language destination
            if (language != "default")
            {
                project.Configuration.Destination = Path.Combine(project.Configuration.Destination, language);
            }

            // Set the language of the project
            project.Language = language;

            // Load translation provider
            project.Translations = new TranslationProvider(project);

            // Assign a provider
            project.Assets     = new DiskAssetProvider(path);
            project.ViewEngine = new RazorViewEngine(project);

            // We have a project!
            return(project);
        }
        /// <summary>
        /// Builds the project.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="mode"></param>
        public static void Bake(DirectoryInfo path, BakeMode mode)
        {
            // Read the configuration file at destination
            var config = SiteConfig.Read(path);

            if (config.Languages == null || config.Languages.Count == 0)
            {
                // Make sure we have a default language
                config.Languages = new List <string>();
                config.Languages.Add("default");
            }

            Tracing.Info("Bake", "Baking: " + path.FullName);

            foreach (var language in config.Languages)
            {
                // Load the project and fetch the files
                using (var project = SiteProject.FromDisk(path, language))
                {
                    // Bake the project
                    project.Bake(mode);
                }
            }
        }