Exemple #1
0
        public static List <SinglePage> GetAncestors(IRecordCollectorFile current)
        {
            if (current == null)
            {
                throw new ArgumentNullException(nameof(current));
            }

            var ancestors = new List <SinglePage>();
            var original  = current;
            var input     = current;

            while (true)
            {
                if (input.ParentPage != null)
                {
                    ancestors.Add(input.ParentPage);
                    input = input.ParentPage;
                }
                else
                {
                    if (original.Level == -1 && ancestors.Count > 0)
                    {
                        original.Level = ancestors.Count;
                    }

                    return(ancestors);
                }
            }
        }
        private static void CopyFileResource(IRecordCollectorFile file, ContentProperties contentProperties)
        {
            var fileInfo = new FileInfo(file.FullName);

            if (fileInfo.DirectoryName == null)
            {
                return;
            }

            var directoryFromRoot = fileInfo.DirectoryName
                                    .Replace(
                contentProperties.ContentRootPath,
                string.Empty,
                StringComparison.OrdinalIgnoreCase);

            var fileFromRoot = file.FullName
                               .Replace(
                contentProperties.ContentRootPath,
                string.Empty,
                StringComparison.OrdinalIgnoreCase);

            var destinationDirectory = Path.Combine(contentProperties.StaticSiteRootPath, directoryFromRoot);
            var destinationFile      = Path.Combine(contentProperties.StaticSiteRootPath, fileFromRoot);

            Directory.CreateDirectory(destinationDirectory);
            File.Copy(file.FullName, destinationFile, true);
        }
Exemple #3
0
        public static List <SinglePage> GetSiblingsAndSetNextAndPrevious(IRecordCollectorFile current, List <IRecordCollectorFile> allFileModels)
        {
            if (current == null)
            {
                throw new ArgumentNullException(nameof(current));
            }

            var allOnSameLevel = allFileModels
                                 .Where(x =>
                                        x.GetType() == typeof(SinglePage) &&
                                        x.Section == current.Section &&
                                        x.ClosestSectionDirectory != null &&
                                        current.ClosestSectionDirectory != null &&
                                        x.ClosestSectionDirectory.Equals(
                                            current.ClosestSectionDirectory,
                                            StringComparison.OrdinalIgnoreCase))
                                 .Select(x => (SinglePage)x)
                                 .Where(x => !x.Headless)
                                 .OrderByDescending(x => x.Date)
                                 .ToList();

            var i = 0;

            foreach (var sp in allOnSameLevel)
            {
                if (sp.FullName.Equals(
                        current.FullName,
                        StringComparison.OrdinalIgnoreCase))
                {
                    if (i > 0 && allOnSameLevel.Count > i - 1)
                    {
                        var previous = allOnSameLevel[i - 1];
                        current.PreviousPage = previous;
                    }

                    if (allOnSameLevel.Count > i + 1 && allOnSameLevel.Count > 1)
                    {
                        var next = allOnSameLevel[i + 1];
                        current.NextPage = next;
                        break;
                    }
                }

                i++;
            }

            return(allOnSameLevel
                   .Where(x => !x.FullName.Equals(
                              current.FullName,
                              StringComparison.OrdinalIgnoreCase))
                   .ToList());
        }
        private int GetSortOrder(IRecordCollectorFile file)
        {
            if (file.GetType() == typeof(ListPage))
            {
                return 0;
            }

            if (file.GetType() == typeof(SinglePage))
            {
                return 1;
            }

            return 2;
        }
        private static string CreateDirectoryAndGetFilePath(IRecordCollectorFile page, ContentProperties contentProperties)
        {
            var relativePath = page.RelativeUrl.ToString()
                               .Replace(
                "/",
                Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture),
                StringComparison.Ordinal);

            if (relativePath.EndsWith(Path.DirectorySeparatorChar))
            {
                relativePath += "index.html";
            }

            relativePath = relativePath.TrimStart(Path.DirectorySeparatorChar);

            var destinationFile      = Path.Combine(contentProperties.StaticSiteRootPath, relativePath);
            var destinationDirectory = Path.GetDirectoryName(destinationFile);

            Directory.CreateDirectory(destinationDirectory);
            return(destinationFile);
        }