示例#1
0
        public void CanGetDefaultLayout()
        {
            var command = new LoadSiteConfigCommand() { ConfigPath = "data\\site.config" };
            var config = command.ExecuteAsync().Result;

            var site = new Site(config, Enumerable.Empty<DataFile>(), Enumerable.Empty<DocumentFile>(), Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>());

            Assert.Equal("test", site.DefaultLayoutForExtension["html"]);
        }
示例#2
0
        public void CanGetDefaultUrlFromData()
        {
            var command = new LoadSiteConfigCommand() { ConfigPath = "data\\site.config" };
            var config = command.Execute();
            var site = new Site(config, Enumerable.Empty<DataFile>(), Enumerable.Empty<DocumentFile>(), Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>());

            dynamic data = site; //site.GetAsDynamic();

            Assert.Equal("/blog/", data.Url);
        }
示例#3
0
        public void CanGetFullUrlFromData()
        {
            var command = new LoadSiteConfigCommand() { ConfigPath = "data\\site.config" };
            var config = command.ExecuteAsync().Result;
            var site = new Site(config, Enumerable.Empty<DataFile>(), Enumerable.Empty<DocumentFile>(), Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>());

            dynamic data = site; //site.GetAsDynamic();

            Assert.Equal("http://www.example.com/blog/", data.fullurl);
        }
示例#4
0
        public void CanGetTitle()
        {
            var command = new LoadSiteConfigCommand() { ConfigPath = "data\\site.config" };
            var config = command.ExecuteAsync().Result;

            var site = new Site(config, Enumerable.Empty<DataFile>(), Enumerable.Empty<DocumentFile>(), Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>());

            dynamic data = new DynamicSite(null, site);

            Assert.Equal("Test Blog.", (string)data.tiTle);
        }
示例#5
0
        public void CanLoadSiteConfig()
        {
            //TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dataFolder = Path.GetFullPath(@"data\");

            var command = new LoadSiteConfigCommand() { ConfigPath = dataFolder + "site.config" };
            var config = command.ExecuteAsync().Result;

            Assert.Empty(config.SubsiteConfigs);
            Assert.Equal(dataFolder + @"build\here\", config.OutputPath);
            //Assert.Equal(tzi, config.TimeZone);
        }
示例#6
0
        public void CanLoadSiteConfigWithSubsites()
        {
            TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dataFolder = Path.GetFullPath(@"data\");

            var command = new LoadSiteConfigCommand() { ConfigPath = dataFolder + "parent.config" };
            var config = command.ExecuteAsync().Result;

            Assert.Equal(dataFolder + @"parent_build\", config.OutputPath);
            Assert.NotEmpty(config.SubsiteConfigs);
            Assert.Equal(1, config.SubsiteConfigs.Length);
            foreach (var subsite in config.SubsiteConfigs)
            {
                Assert.Equal(config, subsite.Parent);
            }
        }
示例#7
0
        public void CanGetFilesToIgnore()
        {
            //TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dataFolder = Path.GetFullPath(@"data\");

            var command = new LoadSiteConfigCommand() { ConfigPath = dataFolder + "site.config" };
            var config = command.Execute();

            Assert.Equal(2, config.IgnoreFiles.Count());

            var match = config.IgnoreFiles.First();
            Assert.True(match.IsMatch("foo.abc~"));
            Assert.True(match.IsMatch("a.b~"));
            Assert.False(match.IsMatch("foo.abc"));
            Assert.False(match.IsMatch("a.b"));

            match = config.IgnoreFiles.Skip(1).Single();
            Assert.True(match.IsMatch("bar.tmp"));
            Assert.True(match.IsMatch("foo.TMP"));
        }
        public void CanLoadWithAdditionalMetadata()
        {
            var dataFolder = Path.GetFullPath(@"data\additional-metadata\");
            var outputPath = Path.GetFullPath("output");

            var loadConfig = new LoadSiteConfigCommand() { ConfigPath = dataFolder + "site.json" };
            var config = loadConfig.ExecuteAsync().Result;

            var loadData = new LoadDataFilesCommand(config.DataPath, config.AdditionalMetadataForFiles, config.IgnoreFiles);
            loadData.ExecuteAsync().Wait();

            var loadDocuments = new LoadDocumentsCommand();
            loadDocuments.Author = new Author();
            loadDocuments.DocumentsPath = config.DocumentsPath;
            loadDocuments.OutputRootPath = config.OutputPath;
            loadDocuments.AdditionalMetadataForFiles = config.AdditionalMetadataForFiles;
            loadDocuments.IgnoreFiles = config.IgnoreFiles;
            loadDocuments.RenderedExtensions = new[] { "md" };
            loadDocuments.RootUrl = config.RootUrl;
            loadDocuments.ApplicationUrl = config.Url;
            loadDocuments.ExecuteAsync().Wait();

            var data = loadData.DataFiles.Single();
            var document = loadDocuments.Documents.Single();

            Assert.Equal("bar", data.Metadata.Get<string>("foo"));
            Assert.Equal("quux", document.Metadata.Get<string>("baz"));
        }
        public async Task<SiteConfig> ExecuteAsync()
        {
            var root = Path.GetFullPath(Path.GetDirectoryName(this.ConfigPath));

            var settings = new JsonSerializerSettings();
            settings.Converters.Add(new JsonTimeZoneConverter());

            string json;
            using (var reader = new StreamReader(this.ConfigPath))
            {
                json = await reader.ReadToEndAsync();
            }

            var config = new SiteConfig();
            config.Parent = this.Parent;

            var ignoreFiles = new string[0];
            var subsites = new string[0];

            //var config = JsonConvert.DeserializeObject<SiteConfig>(json, settings);
            foreach (var token in JObject.Parse(json))
            {
                var key = token.Key.ToLowerInvariant();
                var value = token.Value;

                switch (key)
                {
                    case "author":
                        config.Author = value.ToObject<Author>();
                        break;

                    case "output":
                    case "outputpath":
                        config.OutputPath = Path.Combine(root, (string)value).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).EnsureBackslashTerminated();
                        break;

                    case "url":
                        config.Url = (string)value;
                        break;

                    case "rooturl":
                        config.RootUrl = (string)value;
                        break;

                    case "subsites":
                        subsites = value.Values<string>().ToArray();
                        break;

                    case "additionalmetadata":
                        config.AdditionalMetadataForFiles = this.ParseAdditionalMetadata(value).ToList();
                        break;

                    case "defaultlayoutforextension":
                        this.AssignDefaultLayouts(config, value);
                        break;

                    case "ignorefiles":
                        config.IgnoreFiles = this.ParseIgnoreFiles(value.Values<string>()).ToArray();
                        break;

                    default:
                        config.Metadata.Add(key, value);
                        break;
                }
            }

            config.SitePath = root;
            config.DataPath = Path.Combine(root, "data\\");
            config.DocumentsPath = Path.Combine(root, "documents\\");
            config.FilesPath = Path.Combine(root, "files\\");
            config.LayoutsPath = Path.Combine(root, "layouts\\");

            config.OutputPath = config.OutputPath ?? Path.Combine(root, "build\\");
            config.Url = config.Url.EnsureStartsWith("/");
            config.RootUrl = config.RootUrl ?? "http://localhost/";

            // If override output path was provided use that.
            config.OutputPath = String.IsNullOrEmpty(this.OutputPath) ? Path.GetFullPath(config.OutputPath) : Path.GetFullPath(this.OutputPath);

            var subsiteLoadTasks = new List<Task<SiteConfig>>(subsites.Length);

            foreach (var subsite in subsites)
            {
                var command = new LoadSiteConfigCommand();
                command.Parent = config;
                command.ConfigPath = Path.Combine(root, subsite);
                var task = command.ExecuteAsync();

                subsiteLoadTasks.Add(task);
            }

            config.SubsiteConfigs = await Task.WhenAll(subsiteLoadTasks);

            return this.SiteConfig = config;
        }
示例#10
0
        private SiteConfig LoadConfig(string sitePath, string outputPath)
        {
            using (var capture = Statistics.Current.Start(StatisticTiming.LoadedConfiguration))
            {
                var configPath = Path.Combine(sitePath, "site.json");
                if (!File.Exists(configPath))
                {
                    configPath = Path.Combine(sitePath, "site.config");
                }

                var command = new LoadSiteConfigCommand();
                command.ConfigPath = configPath;
                command.OutputPath = outputPath;
                return command.Execute();
            }
        }
        public async Task <SiteConfig> ExecuteAsync()
        {
            var root = Path.GetFullPath(Path.GetDirectoryName(this.ConfigPath));

            var settings = new JsonSerializerSettings();

            settings.Converters.Add(new JsonTimeZoneConverter());

            string json;

            using (var reader = new StreamReader(this.ConfigPath))
            {
                json = await reader.ReadToEndAsync();
            }

            var config = new SiteConfig();

            config.Parent = this.Parent;

            var subsites = new string[0];

            //var config = JsonConvert.DeserializeObject<SiteConfig>(json, settings);
            foreach (var token in JObject.Parse(json))
            {
                var key   = token.Key.ToLowerInvariant();
                var value = token.Value;

                switch (key)
                {
                case "author":
                    config.Author = value.ToObject <Author>();
                    break;

                case "output":
                case "outputpath":
                    config.OutputPath = Path.Combine(root, (string)value).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).EnsureBackslashTerminated();
                    break;

                case "url":
                    config.Url = (string)value;
                    break;

                case "rooturl":
                    config.RootUrl = (string)value;
                    break;

                case "subsites":
                    subsites = value.Values <string>().ToArray();
                    break;

                default:
                    config.Metadata.Add(key, value);
                    break;
                }
            }

            config.DocumentsPath = Path.Combine(root, "documents\\");
            config.FilesPath     = Path.Combine(root, "files\\");
            config.LayoutsPath   = Path.Combine(root, "layouts\\");

            config.OutputPath = config.OutputPath ?? Path.Combine(root, "build\\");
            config.Url        = config.Url.EnsureStartsWith("/");
            config.RootUrl    = config.RootUrl ?? "http://localhost/";

            // If override output path was provided use that.
            config.OutputPath = String.IsNullOrEmpty(this.OutputPath) ? Path.GetFullPath(config.OutputPath) : Path.GetFullPath(this.OutputPath);

            var subsiteLoadTasks = new List <Task <SiteConfig> >(subsites.Length);

            foreach (var subsite in subsites)
            {
                var command = new LoadSiteConfigCommand();
                command.Parent     = config;
                command.ConfigPath = Path.Combine(root, subsite);
                var task = command.ExecuteAsync();

                subsiteLoadTasks.Add(task);
            }

            config.SubsiteConfigs = await Task.WhenAll(subsiteLoadTasks);

            return(this.SiteConfig = config);
        }