示例#1
0
        private async IAsyncEnumerable <IFile> CompileAssets(IAssetsFolder folder, IPage page, ISite site, ILocation baseLoc)
        {
            foreach (var asset in folder.Assets)
            {
                var thisLoc = baseLoc.Combine(new Location("", asset.FileName, Enumerable.Empty <string>()));

                if (thisLoc.Matches(m_Config.CompilableAssetsFilter))
                {
                    yield return(await CompileAsset(asset, site, page, thisLoc));
                }
                else
                {
                    yield return(new File(thisLoc, asset.Content, asset.Id));
                }
            }

            foreach (var subFolder in folder.Folders)
            {
                var folderLoc = baseLoc.Combine(new Location("", "", new string[] { subFolder.Name }));
                await foreach (var subFolderAsset in CompileAssets(subFolder, page, site, folderLoc))
                {
                    yield return(subFolderAsset);
                }
            }
        }
示例#2
0
 private IAsyncEnumerable <IFile> LoadLibraryItem(string itemName, string subFolder, string[] filters)
 {
     try
     {
         var compsLoc = m_Location.Combine(new Location("", "", new string[] { subFolder, itemName }));
         return(m_FileLoader.LoadFolder(compsLoc, filters));
     }
     catch (Exception ex)
     {
         throw new LibraryItemLoadException(itemName, subFolder, ex);
     }
 }
示例#3
0
        private void LoadAssets(IAssetsFolder folder, List <IFile> assets, ILocation curLoc)
        {
            var pageAssets = assets.Where(a => a.Location.IsInLocation(curLoc, m_Comparison)).ToList();

            var children = pageAssets.Where(p => p.Location.GetParent().IsSame(curLoc, m_Comparison)).ToList();

            folder.Assets.AddRange(children.Select(a =>
            {
                var fileName = a.Location.FileName;

                if (string.IsNullOrEmpty(fileName))
                {
                    //file with no extension
                    fileName = a.Location.Segments.Last();
                }

                return(new Asset(fileName, a.Content, a.Id));
            }));

            children.ForEach(a => assets.Remove(a));
            children.ForEach(a => pageAssets.Remove(a));

            if (pageAssets.Any())
            {
                foreach (var subFolderName in pageAssets.Select(
                             a => GetBaseSegment(a.Location.GetRelative(curLoc))).Distinct(m_Comparer))
                {
                    var subFolder = new AssetsFolder(subFolderName);
                    folder.Folders.Add(subFolder);
                    LoadAssets(subFolder, assets, curLoc.Combine(new Location("", "", new string[] { subFolderName })));
                }
            }
        }
示例#4
0
        private async IAsyncEnumerable <IFile> OnPostAddPublishFiles(ILocation outLoc)
        {
            await Task.CompletedTask;

            foreach (var bundle in m_BundlesContent)
            {
                var parts = bundle.Key.Split(PluginLocation.PathSeparators,
                                             StringSplitOptions.RemoveEmptyEntries);

                var dir      = parts.Take(parts.Length - 1);
                var fileName = parts.Last();

                yield return(new PluginFile(bundle.Value.ToString(), outLoc.Combine(new PluginLocation("", fileName, dir))));
            }

            await foreach (var defStyle in RetrieveDeferredAssets(
                               m_Setts.DeleteUnusedCss, m_DeferredStyles.ToArray(), m_UsedStyles.ToArray(), outLoc))
            {
                yield return(defStyle);
            }

            await foreach (var defScript in RetrieveDeferredAssets(
                               m_Setts.DeleteUnusedJs, m_DeferredScripts.ToArray(), m_UsedScripts.ToArray(), outLoc))
            {
                yield return(defScript);
            }
        }
示例#5
0
        private async IAsyncEnumerable <IFile> CompileAll(IPage page, ISite site, ILocation baseLoc)
        {
            const string PAGE_FILE_NAME = "index.html";

            ILocation thisLoc;

            if (!baseLoc.IsEmpty())
            {
                thisLoc = baseLoc.Combine(new Location("", PAGE_FILE_NAME, new string[] { page.Name }));
            }
            else
            {
                thisLoc = new Location("", PAGE_FILE_NAME, Enumerable.Empty <string>());
            }

            ILocation pageLoc;

            if (!System.IO.Path.HasExtension(page.Name))
            {
                pageLoc = thisLoc;
            }
            else
            {
                pageLoc = baseLoc.Combine(new Location("", page.Name, Enumerable.Empty <string>()));
            }

            if (!(page is IPhantomPage))
            {
                yield return(await CompilePage(page, site, pageLoc));
            }

            await foreach (var asset in CompileAssets(page, page, site, thisLoc))
            {
                yield return(asset);
            }

            foreach (var child in page.SubPages)
            {
                await foreach (var subPage in CompileAll(child, site, thisLoc))
                {
                    yield return(subPage);
                }
            }
        }
示例#6
0
        private async IAsyncEnumerable <IFile> OnPostAddPublishFiles(ILocation outLoc)
        {
            //to remove the warning
            await Task.CompletedTask;

            var opts = new JsonSerializerOptions()
            {
                IgnoreNullValues     = true,
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            var searchContent = JsonSerializer.Serialize(m_SearchIndex, opts).ToString();

            yield return(new PluginFile($"var tipuesearch = {{ \"pages\": {searchContent} }};",
                                        outLoc.Combine(new PluginLocation("", "search-content.js", new string[] { SEARCH_PAGE_NAME }))));
        }
示例#7
0
        private IAsyncEnumerable <IFile> ProcessLibraryItems(string itemType, string itemName,
                                                             SecureLibraryItem[] itemsList, string[] filters)
        {
            var item = itemsList?.FirstOrDefault(i => string.Equals(i.Name, itemName, StringComparison.CurrentCultureIgnoreCase));

            if (item != null)
            {
                var libLoc = m_Loc.Combine(itemType, item.Name);

                try
                {
                    return(LoadAndValidateFiles(libLoc, item.Files, filters));
                }
                catch (Exception ex)
                {
                    throw new LibraryItemLoadException(itemName, libLoc.ToId(), ex);
                }
            }
            else
            {
                throw new UserMessageException($"'{itemName}' item is not present in the secure library manifest");
            }
        }