예제 #1
0
        private void BuildSite(SiteObject site, bool server)
        {
            site.CommandLine.HandleCommonOptions();

            if (site.BaseUrl == null || !site.BaseUrlForce)
            {
                site.BaseUrl = DefaultBaseUrl;
            }
            if (site.BasePath == null || !site.BaseUrlForce)
            {
                site.BasePath = string.Empty;
            }

            if (!noWatchOption.HasValue())
            {
                if (site.GetLiveReload())
                {
                    SetupLiveReloadClient(site);
                    if (server)
                    {
                        SetupLiveReloadServer();
                    }
                }

                site.Build();

                if (server)
                {
                    var watcher = _watcher.Value;
                    watcher.Start();
                    watcher.FileSystemEvents += (sender, args) =>
                    {
                        var newSite = site.Clone();
                        if (site.CanTrace())
                        {
                            site.Info($"Received file events [{args.FileEvents.Count}]");
                        }

                        try
                        {
                            BuildSite(newSite, false);

                            if (newSite.GetLiveReload())
                            {
                                OnSiteRebuildLiveReload(newSite);
                            }
                        }
                        catch (Exception ex)
                        {
                            site.Error($"Unexpected error while reloading the site. Reason: {ex.GetReason()}");
                        }
                    };
                }
            }
            else
            {
                site.Build();
            }
        }
예제 #2
0
            public string GetPath(TemplateContext context, SourceSpan callerSpan, string templateName)
            {
                templateName = templateName.Trim();
                if (templateName.Contains("..") || templateName.StartsWith("/") || templateName.StartsWith("\\"))
                {
                    site.Error(callerSpan, $"The include [{templateName}] cannot contain '..' or start with '/' or '\\'");
                    return(null);
                }
                var templatePath = UPath.Root / IncludesDirectoryName / templateName;

                return((string)templatePath);
            }
예제 #3
0
        public bool TryInstall(SiteObject site, string extend, string version, IFileSystem outputFileSystem)
        {
            if (string.IsNullOrWhiteSpace(version))
            {
                version = "master";
            }

            foreach (var themeDesc in FindAll(site))
            {
                var fullVersion = themeDesc.Url + "/archive/" + version + ".zip";
                if (themeDesc.Name == extend)
                {
                    try
                    {
                        if (site.CanInfo())
                        {
                            site.Info($"Downloading and installing extension/theme `{extend}` to `{outputFileSystem.ConvertPathToInternal(UPath.Root)}`");
                        }

                        using (HttpClient client = new HttpClient())
                        {
                            using (var stream = client.GetStreamAsync(fullVersion).Result)
                            {
                                //site.Content.CreateDirectory(new DirectoryEntry(site.FileSystem, outputFileSystem));

                                using (var zip = new ZipArchive(stream, ZipArchiveMode.Read))
                                {
                                    var    indexOfRepoName = themeDesc.Url.LastIndexOf('/');
                                    string repoName        = themeDesc.Url.Substring(indexOfRepoName + 1);
                                    var    directoryInZip  = $"{repoName}-{version}/{themeDesc.Directory}";
                                    zip.ExtractToDirectory(new DirectoryEntry(outputFileSystem, UPath.Root), directoryInZip);
                                }
                                return(true);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        site.Error($"Unable to load extension/theme from Url [{fullVersion}]. Reason:{ex.GetReason()}");
                        break;
                    }
                }
            }
            return(false);
        }
예제 #4
0
 public string GetPath(TemplateContext context, SourceSpan callerSpan, string templateName)
 {
     site.Error(callerSpan, $"The include statement is not allowed from this context. The include [{templateName}] cannot be loaded");
     return(null);
 }
예제 #5
0
        public IEnumerable <ExtendDescription> FindAll(SiteObject site)
        {
            if (loaded)
            {
                return(cacheList);
            }

            if (RegistryUrl == null)
            {
                site.Error($"The registry Url for {nameof(DefaultExtendProvider)} cannot be null");
                return(cacheList);
            }

            if (site.CanTrace())
            {
                site.Trace($"Checking remote registry [{RegistryUrl}] for available extensions/themes");
            }

            if (site == null)
            {
                throw new ArgumentNullException(nameof(site));
            }
            string themeRegistryStr;

            try
            {
                using (HttpClient client = new HttpClient())
                {
                    themeRegistryStr = client.GetStringAsync(RegistryUrl).Result;
                }
            }
            catch (Exception ex)
            {
                site.Error($"Unable to load theme registry from Url [{RegistryUrl}]. Reason:{ex.GetReason()}");
                return(cacheList);
            }

            var    registryObject = new DynamicObject();
            object result;

            if (site.Scripts.TryImportScript(themeRegistryStr, Name, registryObject, ScriptFlags.None, out result))
            {
                var themeList = registryObject["extensions"] as ScriptArray;
                if (themeList != null)
                {
                    foreach (var theme in themeList)
                    {
                        var themeObject = theme as ScriptObject;
                        if (themeObject != null)
                        {
                            var themeName        = (string)themeObject["name"];
                            var themeDescription = (string)themeObject["description"];
                            var themeUrl         = (string)themeObject["url"];
                            var themeDirectory   = (string)themeObject["directory"];
                            cacheList.Add(new ExtendDescription(themeName, themeDescription, themeUrl, themeDirectory));
                        }
                    }
                }
            }

            loaded = true;
            return(cacheList);
        }